-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy patherror.rb
44 lines (35 loc) · 990 Bytes
/
error.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# tested via spec/core/middleware/response/raise_error_spec.rb
module ZendeskAPI
module Error
class ClientError < Faraday::ClientError
attr_reader :wrapped_exception
def to_s
if response
"#{super} -- #{response.method} #{response.url}"
else
super
end
end
end
class RecordInvalid < ClientError
attr_accessor :errors
def initialize(*)
super
if response[:body].is_a?(Hash)
@errors = response[:body]["details"] || generate_error_msg(response[:body])
end
@errors ||= {}
end
def to_s
"#{self.class.name}: #{@errors}"
end
private
def generate_error_msg(response_body)
response_body.values_at("description", "message", "error", "errors").compact.join(" - ")
end
end
class NetworkError < ClientError; end
class RecordNotFound < ClientError; end
class RateLimited < ClientError; end
end
end