Exception: Increase::ApiError
- Defined in:
- lib/increase/errors.rb
Direct Known Subclasses
ApiMethodNotFoundError, EnvironmentMismatchError, IdempotencyConflictError, IdempotencyUnprocessableError, InsufficientPermissionsError, InternalServerError, InvalidApiKeyError, InvalidOperationError, InvalidParametersError, MalformedRequestError, ObjectNotFoundError, PrivateFeatureError, RateLimitedError
Instance Attribute Summary collapse
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, response: nil, detail: nil, status: nil, title: nil, type: nil) ⇒ ApiError
constructor
A new instance of ApiError.
Constructor Details
#initialize(message, response: nil, detail: nil, status: nil, title: nil, type: nil) ⇒ ApiError
Returns a new instance of ApiError.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/increase/errors.rb', line 14 def initialize(, response: nil, detail: nil, status: nil, title: nil, type: nil) @response = response @detail = detail || response.body["detail"] @status = status || response.body["status"] @title = title || response.body["title"] @type = type || response.body["type"] super() end |
Instance Attribute Details
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
9 10 11 |
# File 'lib/increase/errors.rb', line 9 def detail @detail end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/increase/errors.rb', line 7 def response @response end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/increase/errors.rb', line 10 def status @status end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
11 12 13 |
# File 'lib/increase/errors.rb', line 11 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/increase/errors.rb', line 12 def type @type end |
Class Method Details
.from_response(response) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/increase/errors.rb', line 26 def from_response(response) type = response.body["type"] klass = ERROR_TYPES[type] # Fallback in case of really bad 5xx error klass ||= InternalServerError if (500..599).cover?(response.status) # Handle case of an unknown error klass ||= ApiError code = [response.body["status"] || response.status, type].compact.join(": ") || "Error" = [response.body["title"], response.body["detail"]].compact.join(" ") || "Increase API Error" klass.new("[#{code}] #{}", response: response) end |