Exception: Paysafe::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Paysafe::Error
- Defined in:
- lib/paysafe/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)
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_BY_STATUS =
{ 400 => Paysafe::Error::BadRequest, 401 => Paysafe::Error::Unauthorized, 402 => Paysafe::Error::RequestDeclined, 403 => Paysafe::Error::Forbidden, 404 => Paysafe::Error::NotFound, 406 => Paysafe::Error::NotAcceptable, 409 => Paysafe::Error::Conflict, 415 => Paysafe::Error::UnsupportedMediaType, 422 => Paysafe::Error::UnprocessableEntity, 429 => Paysafe::Error::TooManyRequests, 500 => Paysafe::Error::InternalServerError, 502 => Paysafe::Error::BadGateway, 503 => Paysafe::Error::ServiceUnavailable, 504 => Paysafe::Error::GatewayTimeout, }
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
The Paysafe API Error Code.
-
#response ⇒ Hash
readonly
The JSON HTTP response in Hash form.
Class Method Summary collapse
-
.from_response(body, status) ⇒ Paysafe::Error
Create a new error from an HTTP response.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(message: '', code: nil, response: {}) ⇒ Paysafe::Error
constructor
Initializes a new Error object.
- #merchant_ref_num ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(message: '', code: nil, response: {}) ⇒ Paysafe::Error
Initializes a new Error object
107 108 109 110 111 |
# File 'lib/paysafe/error.rb', line 107 def initialize(message: '', code: nil, response: {}) @code = code @response = response super() end |
Instance Attribute Details
#code ⇒ String (readonly)
The Paysafe API Error Code
94 95 96 |
# File 'lib/paysafe/error.rb', line 94 def code @code end |
#response ⇒ Hash (readonly)
The JSON HTTP response in Hash form
99 100 101 |
# File 'lib/paysafe/error.rb', line 99 def response @response end |
Class Method Details
.from_response(body, status) ⇒ Paysafe::Error
Create a new error from an HTTP response
74 75 76 77 78 |
# File 'lib/paysafe/error.rb', line 74 def from_response(body, status) klass = ERRORS_BY_STATUS[status] || Paysafe::Error , error_code = parse_error(body) klass.new(message: , code: error_code, response: body) end |
Instance Method Details
#id ⇒ Object
117 118 119 |
# File 'lib/paysafe/error.rb', line 117 def id response.dig(:id) if response.is_a?(Hash) end |
#merchant_ref_num ⇒ Object
121 122 123 |
# File 'lib/paysafe/error.rb', line 121 def merchant_ref_num response.dig(:merchant_ref_num) if response.is_a?(Hash) end |
#to_s ⇒ Object
113 114 115 |
# File 'lib/paysafe/error.rb', line 113 def to_s [ super, code_text, field_error_text, detail_text ].compact.join(' ') end |