class SynapsePayRest::Error
Custom class for handling HTTP and API errors.
Constants
- BadGateway
Raised on the HTTP status code 502
- BadRequest
Raised on the HTTP status code 400
- ClientError
Raised on a 4xx HTTP status code
- Conflict
Raised on the HTTP status code 409
- ERRORS
HTTP status code to
Error
subclass mapping@todo need to add an error message for various 202 cases (fingerprint, mfa, etc) @todo doesn't do well when there's an html response from nginx for bad gateway/timeout
- Forbidden
Raised on the HTTP status code 403
- GatewayTimeout
Raised on the HTTP status code 504
- InternalServerError
Raised on the HTTP status code 500
- NotAcceptable
Raised on the HTTP status code 406
- NotFound
Raised on the HTTP status code 404
- RequestDeclined
Raised on the HTTP status code 402
- ServerError
Raised on a 5xx HTTP status code
Raised on the HTTP status code 503
- TooManyRequests
Raised on the HTTP status code 429
Raised on the HTTP status code 401
- UnprocessableEntity
Raised on the HTTP status code 422
- UnsupportedMediaType
Raised on the HTTP status code 415
Attributes
The SynapsePay API Error
Code
@return [Integer]
The JSON HTTP response in Hash form
@return [Hash]
Public Class Methods
Create a new error from an HTTP response
@param body [String] @param code [Integer] @return [SynapsePayRest::Error]
# File lib/synapse_pay_rest/error.rb, line 89 def from_response(body) message, error_code, http_code = parse_error(body) http_code = http_code.to_s klass = ERRORS[http_code] || SynapsePayRest::Error klass.new(message: message, code: error_code, response: body) end
Initializes a new Error
object
@param message [Exception, String] @param code [Integer] @param response [Hash] @return [SynapsePayRest::Error]
# File lib/synapse_pay_rest/error.rb, line 115 def initialize(message: '', code: nil, response: {}) super(message) @code = code @response = response end
Private Class Methods
# File lib/synapse_pay_rest/error.rb, line 98 def parse_error(body) if body.nil? || body.empty? ['', nil, nil] elsif body.is_a?(Hash) && body['error'].is_a?(Hash) [body['error']['en'], body['error_code'], body['http_code']] elsif body.is_a?(Hash) && body[:error].is_a?(Hash) [body[:error][:en], body[:error_code], body[:http_code]] end end