Exception: SynapsePayRest::Error
- Inherits:
-
StandardError
- Object
- StandardError
- SynapsePayRest::Error
- Defined in:
- lib/synapse_pay_rest/error.rb
Overview
Custom class for handling HTTP and API errors.
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)
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)
Class.new(ServerError)
- GatewayTimeout =
Raised on the HTTP status code 504
Class.new(ServerError)
- ERRORS =
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
HTTP status code to Error subclass mapping
{ '400' => SynapsePayRest::Error::BadRequest, '401' => SynapsePayRest::Error::Unauthorized, '402' => SynapsePayRest::Error::RequestDeclined, '403' => SynapsePayRest::Error::Forbidden, '404' => SynapsePayRest::Error::NotFound, '406' => SynapsePayRest::Error::NotAcceptable, '409' => SynapsePayRest::Error::Conflict, '415' => SynapsePayRest::Error::UnsupportedMediaType, '422' => SynapsePayRest::Error::UnprocessableEntity, '429' => SynapsePayRest::Error::TooManyRequests, '500' => SynapsePayRest::Error::InternalServerError, '502' => SynapsePayRest::Error::BadGateway, '503' => SynapsePayRest::Error::ServiceUnavailable, '504' => SynapsePayRest::Error::GatewayTimeout }.freeze
Instance Attribute Summary collapse
-
#code ⇒ Integer
readonly
The SynapsePay API Error Code.
-
#response ⇒ Hash
readonly
The JSON HTTP response in Hash form.
Class Method Summary collapse
-
.from_response(body) ⇒ SynapsePayRest::Error
Create a new error from an HTTP response.
Instance Method Summary collapse
-
#initialize(message: '', code: nil, response: {}) ⇒ SynapsePayRest::Error
constructor
Initializes a new Error object.
Constructor Details
#initialize(message: '', code: nil, response: {}) ⇒ SynapsePayRest::Error
Initializes a new Error object
115 116 117 118 119 |
# File 'lib/synapse_pay_rest/error.rb', line 115 def initialize(message: '', code: nil, response: {}) super() @code = code @response = response end |
Instance Attribute Details
#code ⇒ Integer (readonly)
The SynapsePay API Error Code
76 77 78 |
# File 'lib/synapse_pay_rest/error.rb', line 76 def code @code end |
#response ⇒ Hash (readonly)
The JSON HTTP response in Hash form
81 82 83 |
# File 'lib/synapse_pay_rest/error.rb', line 81 def response @response end |
Class Method Details
.from_response(body) ⇒ SynapsePayRest::Error
Create a new error from an HTTP response
89 90 91 92 93 94 |
# File 'lib/synapse_pay_rest/error.rb', line 89 def from_response(body) , error_code, http_code = parse_error(body) http_code = http_code.to_s klass = ERRORS[http_code] || SynapsePayRest::Error klass.new(message: , code: error_code, response: body) end |