Exception: Anypost::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/anypost/errors.rb

Overview

Base class for every error raised by the SDK.

Branch on #type (the stable, machine-readable code) rather than on the HTTP status or the message text.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, type:, status: nil, request_id: nil, raw: nil) ⇒ Error

Returns a new instance of Error.



20
21
22
23
24
25
26
# File 'lib/anypost/errors.rb', line 20

def initialize(message, type:, status: nil, request_id: nil, raw: nil)
  super(message)
  @type = type
  @status = status
  @request_id = request_id
  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the parsed response body, or the underlying cause.

Returns:

  • (Object)

    the parsed response body, or the underlying cause



18
19
20
# File 'lib/anypost/errors.rb', line 18

def raw
  @raw
end

#request_idString? (readonly)

Returns request id from the response, when present.

Returns:

  • (String, nil)

    request id from the response, when present



16
17
18
# File 'lib/anypost/errors.rb', line 16

def request_id
  @request_id
end

#statusInteger? (readonly)

Returns HTTP status, or nil when no response was received.

Returns:

  • (Integer, nil)

    HTTP status, or nil when no response was received



14
15
16
# File 'lib/anypost/errors.rb', line 14

def status
  @status
end

#typeString (readonly)

Returns stable, machine-readable error type.

Returns:

  • (String)

    stable, machine-readable error type



12
13
14
# File 'lib/anypost/errors.rb', line 12

def type
  @type
end