Exception: Bunq::ResponseError
- Inherits:
-
StandardError
- Object
- StandardError
- Bunq::ResponseError
- Defined in:
- lib/bunq/errors.rb
Direct Known Subclasses
AbsentResponseSignature, InvalidResponseSignature, MaintenanceResponse, ResourceNotFound, TooManyRequestsResponse, UnauthorisedResponse, UnexpectedResponse
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#errors ⇒ Array|nil
Returns an array of errors returned from the API, or nil if no errors are returned.
-
#initialize(msg = 'Response error', code: nil, headers: nil, body: nil) ⇒ ResponseError
constructor
A new instance of ResponseError.
-
#parsed_body(opts = {}) ⇒ Object
Returns the parsed body if it is a JSON document, nil otherwise.
Constructor Details
#initialize(msg = 'Response error', code: nil, headers: nil, body: nil) ⇒ ResponseError
Returns a new instance of ResponseError.
9 10 11 12 13 14 |
# File 'lib/bunq/errors.rb', line 9 def initialize(msg = 'Response error', code: nil, headers: nil, body: nil) @code = code @headers = headers || {} @body = body super("#{msg} (code: #{code}, body: #{body})") end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/bunq/errors.rb', line 7 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/bunq/errors.rb', line 5 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/bunq/errors.rb', line 6 def headers @headers end |
Instance Method Details
#errors ⇒ Array|nil
Returns an array of errors returned from the API, or nil if no errors are returned.
29 30 31 32 |
# File 'lib/bunq/errors.rb', line 29 def errors json = parsed_body json ? json['Error'] : nil end |
#parsed_body(opts = {}) ⇒ Object
Returns the parsed body if it is a JSON document, nil otherwise.
18 19 20 21 22 23 24 25 |
# File 'lib/bunq/errors.rb', line 18 def parsed_body(opts = {}) if @body && @headers['content-type'] && @headers['content-type'].include?('application/json') JSON.parse( @body, opts, ) end end |