Exception: SynapsePayments::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/synapse_payments/error.rb

Constant Summary collapse

ClientError =

Raised on a 4xx HTTP status code

Class.new(self)
BadRequest =

Raised on the HTTP status code 400

Class.new(ClientError)
Unauthorized =

Raised on the HTTP status code 401

Class.new(ClientError)
RequestDeclined =

Raised on the HTTP status code 402

Class.new(ClientError)
Forbidden =

Raised on the HTTP status code 403

Class.new(ClientError)
NotFound =

Raised on the HTTP status code 404

Class.new(ClientError)
NotAcceptable =

Raised on the HTTP status code 406

Class.new(ClientError)
Conflict =

Raised on the HTTP status code 409

Class.new(ClientError)
UnsupportedMediaType =

Raised on the HTTP status code 415

Class.new(ClientError)
UnprocessableEntity =

Raised on the HTTP status code 422

Class.new(ClientError)
TooManyRequests =

Raised on the HTTP status code 429

Class.new(ClientError)
ServerError =

Raised on a 5xx HTTP status code

Class.new(self)
InternalServerError =

Raised on the HTTP status code 500

Class.new(ServerError)
BadGateway =

Raised on the HTTP status code 502

Class.new(ServerError)
ServiceUnavailable =

Raised on the HTTP status code 503

Class.new(ServerError)
GatewayTimeout =

Raised on the HTTP status code 504

Class.new(ServerError)
ERRORS =
{
  400 => SynapsePayments::Error::BadRequest,
  401 => SynapsePayments::Error::Unauthorized,
  402 => SynapsePayments::Error::RequestDeclined,
  403 => SynapsePayments::Error::Forbidden,
  404 => SynapsePayments::Error::NotFound,
  406 => SynapsePayments::Error::NotAcceptable,
  409 => SynapsePayments::Error::Conflict,
  415 => SynapsePayments::Error::UnsupportedMediaType,
  422 => SynapsePayments::Error::UnprocessableEntity,
  429 => SynapsePayments::Error::TooManyRequests,
  500 => SynapsePayments::Error::InternalServerError,
  502 => SynapsePayments::Error::BadGateway,
  503 => SynapsePayments::Error::ServiceUnavailable,
  504 => SynapsePayments::Error::GatewayTimeout,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message: '', code: nil, response: {}) ⇒ SynapsePayments::Error

Initializes a new Error object

Parameters:

  • message (Exception, String) (defaults to: '')
  • code (Integer) (defaults to: nil)
  • response (Hash) (defaults to: {})


110
111
112
113
114
# File 'lib/synapse_payments/error.rb', line 110

def initialize(message: '', code: nil, response: {})
  super(message)
  @code = code
  @response = response
end

Instance Attribute Details

#codeInteger (readonly)

The SynapsePay API Error Code

Returns:

  • (Integer)


71
72
73
# File 'lib/synapse_payments/error.rb', line 71

def code
  @code
end

#responseHash (readonly)

The JSON HTTP response in Hash form

Returns:

  • (Hash)


76
77
78
# File 'lib/synapse_payments/error.rb', line 76

def response
  @response
end

Class Method Details

.error_from_response(body, code) ⇒ SynapsePayments::Error

Create a new error from an HTTP response

Parameters:

  • body (String)
  • code (Integer)

Returns:



84
85
86
87
88
# File 'lib/synapse_payments/error.rb', line 84

def error_from_response(body, code)
  klass = ERRORS[code] || SynapsePayments::Error
  message, error_code = parse_error(body)
  klass.new(message: message, code: error_code, response: body)
end