-
Notifications
You must be signed in to change notification settings - Fork 3
/
errors.rb
52 lines (42 loc) · 1.37 KB
/
errors.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
45
46
47
48
49
50
51
52
class Postmen
# Generic Exception class, all other exceptions should inherit from this class
Error = Class.new(StandardError)
# Generic exception raised if the API returns an error
class RequestError < Error
extend Forwardable
def_delegators :@request, :meta
def initialize(request)
@request = request
end
# Indicates whether request is retryable.
# @see https://docs.postmen.com/errors.html API Documentation
def retryable?
meta.fetch(:retryable, false)
end
# Returns details for the request error
# @see https://docs.postmen.com/#meta API Documentation
def details
meta[:details]
end
# Internal API error code
# @see https://docs.postmen.com/errors.html List of Error codes
def code
meta[:code]
end
# Returns human-readable error message
# @see https://docs.postmen.com/#meta API Documentation
def message
meta[:message]
end
private
attr_reader :request
end
# Exception raised if rate limit was exceeded
RateLimitExceeded = Class.new(Error)
# Exception raised in case of any connection error
ConnectionError = Class.new(Error)
# Exception raised if retriable request reached maximum number of attempts.
MaximumNumberOfRetriesReachedError = Class.new(Error)
# Expcetion raised if resource was not found.
ResourceNotFound = Class.new(RequestError)
end