Exception: Billomat::GatewayError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/billomat/gateway.rb

Overview

Raised if something goes wrong during an API call.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_exception) ⇒ GatewayError

Create a new GatewayError from a RestClient exception.

Parameters:

  • original_exception (RestClient::Exception)

    the original exception



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/billomat/gateway.rb', line 14

def initialize(original_exception)
  # Extract the error from the response if it is present. If no error
  # could be extracted, use the whole body
  body = original_exception.response&.body
  response_error = JSON.parse(body).dig('errors', 'error') || body if body

  # Use the default message and append our detailed error
  message = original_exception.default_message
  message += " ('#{response_error}')" if response_error

  super(message)
  @original_exception = original_exception
end

Instance Attribute Details

#original_exceptionObject (readonly)

Returns the value of attribute original_exception.



9
10
11
# File 'lib/billomat/gateway.rb', line 9

def original_exception
  @original_exception
end