class Paysafe::Error
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_BY_STATUS
- 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 JSON HTTP response in Hash form
@return [Hash]
Public Class Methods
Create a new error from an HTTP response
@param body [String] @param status [Integer] @return [Paysafe::Error]
# File lib/paysafe/error.rb, line 74 def from_response(body, status) klass = ERRORS_BY_STATUS[status] || Paysafe::Error message, error_code = parse_error(body) klass.new(message: message, code: error_code, response: body) end
Initializes a new Error
object
@param message [Exception, String] @param code [String] @param response [Hash] @return [Paysafe::Error]
# File lib/paysafe/error.rb, line 107 def initialize(message: '', code: nil, response: {}) @code = code @response = response super(message) end
Private Class Methods
# File lib/paysafe/error.rb, line 82 def parse_error(body) if body.is_a?(Hash) [ body.dig(:error, :message), body.dig(:error, :code) ] else [ '', nil ] end end
Public Instance Methods
# File lib/paysafe/error.rb, line 117 def id response.dig(:id) if response.is_a?(Hash) end
# File lib/paysafe/error.rb, line 121 def merchant_ref_num response.dig(:merchant_ref_num) if response.is_a?(Hash) end
# File lib/paysafe/error.rb, line 113 def to_s [ super, code_text, field_error_text, detail_text ].compact.join(' ') end
Private Instance Methods
# File lib/paysafe/error.rb, line 127 def code_text "(Code #{code})" if code end
# File lib/paysafe/error.rb, line 142 def detail_text "Details: #{details.join('. ')}".strip if details end
# File lib/paysafe/error.rb, line 146 def details response.dig(:error, :details) if response.is_a?(Hash) end
# File lib/paysafe/error.rb, line 131 def field_error_text if field_errors msgs = field_errors.map { |f| "The \`#{f[:field]}\` #{f[:error]}." }.join(' ') "Field Errors: #{msgs}".strip end end
# File lib/paysafe/error.rb, line 138 def field_errors response.dig(:error, :field_errors) if response.is_a?(Hash) end