Exception: WorldpayCnp::Error

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

Constant Summary collapse

InvalidFormatError =
Class.new(self)
XmlParseError =
Class.new(self)
ClientError =

Raised on a 4xx HTTP status code

Class.new(self)
Forbidden =

Raised on the HTTP status code 403

Class.new(ClientError)
NotFound =

Raised on the HTTP status code 404

Class.new(ClientError)
MethodNotAllowed =

Raised on the HTTP status code 405

Class.new(ClientError)
ExpectationFailed =

Raised on the HTTP status code 417

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_BY_STATUS =
{
  403 => Error::Forbidden,
  404 => Error::NotFound,
  405 => Error::MethodNotAllowed,
  417 => Error::ExpectationFailed,
  500 => Error::InternalServerError,
  502 => Error::BadGateway,
  503 => Error::ServiceUnavailable,
  504 => Error::GatewayTimeout,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, response_code: '', raw_response: '') ⇒ WorldpayCnp::Error

Initializes a new Error object

Parameters:

  • message (Exception, String)
  • code (String)
  • raw_http_response (String)


79
80
81
82
83
# File 'lib/worldpay_cnp/error.rb', line 79

def initialize(message, response_code: '', raw_response: '')
  @response_code = response_code
  @raw_response = raw_response
  super(message)
end

Instance Attribute Details

#raw_responseString (readonly)

The raw HTTP response, if applicable

Returns:

  • (String)


62
63
64
# File 'lib/worldpay_cnp/error.rb', line 62

def raw_response
  @raw_response
end

#response_codeString (readonly)

The response code in the XML root element. The value of the response attribute in the following example:

<cnpOnlineResponse version=“12.17” xmlns=“www.vantivcnp.com/schema

response="1" message="Error validating xml..." />

Returns:

  • (String)


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

def response_code
  @response_code
end

Class Method Details

.from_http_response(body, status) ⇒ WorldpayCnp::Error

Create a new error from an HTTP response body and status

Parameters:

  • body (String)
  • status (Integer)

Returns:



53
54
55
56
# File 'lib/worldpay_cnp/error.rb', line 53

def from_http_response(body, status)
  klass = ERRORS_BY_STATUS[status] || self
  klass.new("Service error (Status: #{status})", raw_response: body)
end