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, request) ⇒ Error

Returns a new instance of Error.



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

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



46
47
48
# File 'lib/quickpay/api/error.rb', line 46

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



46
47
48
# File 'lib/quickpay/api/error.rb', line 46

def headers
  @headers
end

#requestObject (readonly)

Returns the value of attribute request.



46
47
48
# File 'lib/quickpay/api/error.rb', line 46

def request
  @request
end

#statusObject (readonly)

Returns the value of attribute status.



46
47
48
# File 'lib/quickpay/api/error.rb', line 46

def status
  @status
end

Class Method Details

.by_status_code(status, body, headers, request) ⇒ Object



61
62
63
64
65
# File 'lib/quickpay/api/error.rb', line 61

def self.by_status_code(status, body, headers, request)
  return if (200..399).cover? status

  CLASS_MAP.fetch(status, QuickPay::API::Error).new(status, body, headers, request)
end

Instance Method Details

#to_sObject Also known as: inspect



55
56
57
58
# File 'lib/quickpay/api/error.rb', line 55

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