Exception: Balanced::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Balanced::Error
- Defined in:
- lib/balanced/error.rb,
lib/balanced/resources/order.rb
Overview
Custom error class for rescuing from all API response-related Balanced errors
Direct Known Subclasses
BadGateway, BadRequest, Conflict, Forbidden, FundingInstrumentNotCreditable, FundingInstrumentVerificationError, GatewayTimeout, Gone, InternalServerError, MethodNotAllowed, MoreInformationRequired, NotFound, NotImplemented, PaymentRequired, ServiceUnavailable, StandardError, Unauthorized
Defined Under Namespace
Classes: OrderCancelFailure
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #body ⇒ Hash
- #error_message ⇒ Object
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
8 9 10 11 12 13 |
# File 'lib/balanced/error.rb', line 8 def initialize(response=nil) @response = response unless response.nil? super end end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/balanced/error.rb', line 5 def response @response end |
Instance Method Details
#body ⇒ Hash
16 17 18 19 20 21 |
# File 'lib/balanced/error.rb', line 16 def body @body ||= begin return {} unless response[:body] Utils.indifferent_read_access(response[:body]) end end |
#error_message ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/balanced/error.rb', line 23 def set_attrs errors = body.fetch('errors', nil) unless errors.nil? error = body[:errors][0] extra = error[:additional] ? " -- #{error[:additional]}" : "" "#{self.class.name}(#{response[:status]})::#{error[:status]}:: "\ "#{response[:method].to_s.upcase} #{response[:url].to_s}: "\ "#{error[:category_code]}: #{error[:description]} #{extra}" end end |