Exception: OnlinePayments::SDK::ApiException

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/onlinepayments/sdk/api_exception.rb

Overview

Base class for many exceptions raised by the SDK. It is raised when an error response is received from the Online Payments platform. It contains data about the returned response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, response_body, error_id, errors, message = 'the Online Payments platform returned an error response') ⇒ ApiException

Creates a new ApiException that reports an error response from the Online Payments platform.

Parameters:

  • status_code (Integer)

    HTTP status code the response

  • response_body (String)

    HTTP response body

  • error_id (String)

    error id of the error, may be nil

  • errors (Array<OnlinePayments::SDK::Domain::APIError>)

    a list of errors that occurred, may be empty

  • message (String) (defaults to: 'the Online Payments platform returned an error response')

    error message to include



21
22
23
24
25
26
27
28
# File 'lib/onlinepayments/sdk/api_exception.rb', line 21

def initialize(status_code, response_body, error_id, errors,
               message = 'the Online Payments platform returned an error response')
  super(message)
  @status_code = status_code
  @response_body = response_body
  @error_id = error_id
  @errors = errors || [].freeze
end

Instance Attribute Details

#error_idString (readonly)

An error id corresponding to the error that occurred, if available.

Returns:

  • (String)

    the current value of error_id



12
13
14
# File 'lib/onlinepayments/sdk/api_exception.rb', line 12

def error_id
  @error_id
end

#errorsArray<OnlinePayments::SDK::Domain::APIError> (readonly)

A list of errors received from the Online Payments platform; may be empty but never nil

Returns:



12
13
14
# File 'lib/onlinepayments/sdk/api_exception.rb', line 12

def errors
  @errors
end

#response_bodyString (readonly)

Message body of the returned response.

Returns:

  • (String)

    the current value of response_body



12
13
14
# File 'lib/onlinepayments/sdk/api_exception.rb', line 12

def response_body
  @response_body
end

#status_codeInteger (readonly)

HTTP status code of the returned response.

Returns:

  • (Integer)

    the current value of status_code



12
13
14
# File 'lib/onlinepayments/sdk/api_exception.rb', line 12

def status_code
  @status_code
end

Instance Method Details

#to_sObject



35
36
37
38
39
40
# File 'lib/onlinepayments/sdk/api_exception.rb', line 35

def to_s
  str = super.to_s
  str += "; status_code=#{@status_code}" if @status_code.positive?
  str += "; response_body='#{@response_body}'" if @response_body&.length&.positive?
  str.to_s
end