Exception: NodexPay::APIError

Inherits:
Error
  • Object
show all
Defined in:
lib/nodex_pay/errors.rb,
sig/nodex_pay.rbs

Constant Summary collapse

ERROR_NAMES =

Returns:

  • (Hash[Integer, String])
{
  2010 => "RECEIVED_IDENTIFICATION_TOKEN_EMPTY",
  2011 => "RECEIVED_IDENTIFICATION_TOKEN_INVALID",
  2020 => "RECEIVED_ORDER_CODE_EMPTY",
  2021 => "RECEIVED_ORDER_CODE_DUPLICATE",
  2022 => "RECEIVED_ORDER_CODE_ALREADY_CANCELLED",
  2023 => "PAYMENT_NOT_FOUND",
  2024 => "PAYMENT_NOT_CANCELABLE",
  2030 => "RECEIVED_AMOUNT_INVALID_FORMAT",
  2040 => "RECEIVED_INVALID_CALLBACK_URL",
  2050 => "RECEIVED_COLOR_THEME_INVALID_FORMAT",
  2060 => "RECEIVED_VERIFY_TOKEN_EMPTY",
  2061 => "RECEIVED_VERIFY_TOKEN_INVALID",
  2101 => "RECEIVED_EXT_RESERVED_INVALID",
  2102 => "RECEIVED_EXT_DESCRIPTION_INVALID",
  2370 => "RECEIVE_CONTRACT_UNPUBLISHED",
  2460 => "RECEIVED_INVALID_DEADLINE"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation:, status:, error_codes:, response_headers:, response_body:) ⇒ APIError

Returns a new instance of APIError.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nodex_pay/errors.rb', line 35

def initialize(operation:, status:, error_codes:, response_headers:, response_body:)
  @operation = operation
  @status = status
  @error_codes = error_codes.map { Integer(_1) }.freeze
  @response_headers = response_headers.to_h.transform_keys(&:to_s).transform_values(&:to_s).freeze
  @response_body = response_body.to_s.dup.freeze

  details = @error_codes.map { |code| ERROR_NAMES.fetch(code, code.to_s) }
  suffix = details.empty? ? "" : " (#{details.join(", ")})"
  super("Nodex Pay #{operation} failed with HTTP #{status}#{suffix}")
end

Instance Attribute Details

#error_codesArray[Integer] (readonly)

Returns the value of attribute error_codes.

Returns:

  • (Array[Integer])


33
34
35
# File 'lib/nodex_pay/errors.rb', line 33

def error_codes
  @error_codes
end

#operationSymbol (readonly)

Returns the value of attribute operation.

Returns:

  • (Symbol)


33
34
35
# File 'lib/nodex_pay/errors.rb', line 33

def operation
  @operation
end

#response_bodyString (readonly)

Returns the value of attribute response_body.

Returns:

  • (String)


33
34
35
# File 'lib/nodex_pay/errors.rb', line 33

def response_body
  @response_body
end

#response_headersHash[String, String] (readonly)

Returns the value of attribute response_headers.

Returns:

  • (Hash[String, String])


33
34
35
# File 'lib/nodex_pay/errors.rb', line 33

def response_headers
  @response_headers
end

#statusInteger (readonly)

Returns the value of attribute status.

Returns:

  • (Integer)


33
34
35
# File 'lib/nodex_pay/errors.rb', line 33

def status
  @status
end

Instance Method Details

#inspectObject



47
48
49
# File 'lib/nodex_pay/errors.rb', line 47

def inspect
  "#<#{self.class} operation=#{operation.inspect} status=#{status.inspect} error_codes=#{error_codes.inspect}>"
end