Exception: IronBank::Error
- Inherits:
-
StandardError
- Object
- StandardError
- IronBank::Error
- Defined in:
- lib/iron_bank/error.rb
Overview
Custom error class for rescuing from all Zuora API errors
Direct Known Subclasses
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
- .from_body(response) ⇒ Object
-
.from_response(response) ⇒ Object
Returns the appropriate IronBank::Error subclass based on status and response message.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
- #message_from_body ⇒ Object
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
33 34 35 36 37 38 39 |
# File 'lib/iron_bank/error.rb', line 33 def initialize(response = nil) @response = response = response.is_a?(Faraday::Response) ? : response super() end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
31 32 33 |
# File 'lib/iron_bank/error.rb', line 31 def response @response end |
Class Method Details
.from_body(response) ⇒ Object
25 26 27 28 29 |
# File 'lib/iron_bank/error.rb', line 25 def self.from_body(response) return unless (match = CODE_MATCHER.match(response.body.to_s)) CODE_CLASSES[match.captures.first] end |
.from_response(response) ⇒ Object
Returns the appropriate IronBank::Error subclass based on status and response message
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/iron_bank/error.rb', line 8 def self.from_response(response) klass = case response.status when 200 then from_body(response) when 400 then IronBank::BadRequestError when 401 then IronBank::UnauthorizedError when 404 then IronBank::NotFoundError when 422 then IronBank::UnprocessableEntityError when 429 then IronBank::TooManyRequestsError when 500 then IronBank::InternalServerError when 400..499 then IronBank::ClientError when 500..599 then IronBank::ServerError else IronBank::Error end klass&.new(response) end |
Instance Method Details
#message_from_body ⇒ Object
41 42 43 |
# File 'lib/iron_bank/error.rb', line 41 def response && "Body: #{response.body}" end |