Skip to content

Commit 41555cd

Browse files
committed
custom error
1 parent c103d1b commit 41555cd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/checkhost/client.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
require 'json'
55

66
module CheckHost
7+
class CheckHostError < RuntimeError
8+
@@errors = {
9+
"limit_exceeded" => "Limit of checks is exceeded. Try again in a 10 minutes."
10+
}
11+
def describe_error
12+
puts @@errors.inspect()
13+
if (@@errors.has_key?(message)) then
14+
return @@errors[message]
15+
end
16+
return message
17+
end
18+
end
19+
720
class Client
821
attr_reader :nodes
922

@@ -84,7 +97,7 @@ def query(action, data) # action: newcheck, results; data(hash): newcheck:: type
8497

8598
def parse(json)
8699
res = JSON.parse(json)
87-
raise "#{res['error']}" if res.has_key?('error')
100+
raise CheckHostError.new(res['error']) if res.has_key?('error')
88101
return res
89102
end
90103

0 commit comments

Comments
 (0)