Exception: QuickPay::API::Error

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

Defined Under Namespace

Classes: BadGateway, BadRequest, Conflict, Forbidden, GatewayTimeout, InternalServerError, MethodNotAllowed, NotAcceptable, NotFound, PaymentRequired, ServiceUnavailable, TooManyRequest, Unauthorized

Constant Summary collapse

CLASS_MAP =
{
  400 => "BadRequest",
  401 => "Unauthorized",
  402 => "PaymentRequired",
  403 => "Forbidden",
  404 => "NotFound",
  405 => "MethodNotAllowed",
  406 => "NotAcceptable",
  409 => "Conflict",
  429 => "TooManyRequest",
  500 => "InternalServerError",
  502 => "BadGateway",
  503 => "ServiceUnavailable",
  504 => "GatewayTimeout"
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body, headers) ⇒ Error

Returns a new instance of Error.



36
37
38
39
40
# File 'lib/quickpay/api/error.rb', line 36

def initialize(status, body, headers)
  @status  = status
  @body    = body
  @headers = headers
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



34
35
36
# File 'lib/quickpay/api/error.rb', line 34

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



34
35
36
# File 'lib/quickpay/api/error.rb', line 34

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



34
35
36
# File 'lib/quickpay/api/error.rb', line 34

def status
  @status
end

Class Method Details

.by_status_code(status, body, headers) ⇒ Object



47
48
49
50
51
52
# File 'lib/quickpay/api/error.rb', line 47

def self.by_status_code(status, body, headers)
  raise QuickPay::API::Error.new(status, body, headers) unless CLASS_MAP[status]

  klass = QuickPay::API::Error.const_get(CLASS_MAP[status])
  raise klass.new(status, body, headers)
end

Instance Method Details

#to_sObject Also known as: inspect



42
43
44
# File 'lib/quickpay/api/error.rb', line 42

def to_s
  "#<#{self.class}: status=#{status}, body=#{body.inspect}, headers=#{headers.inspect}>"
end