Exception: Mailfloss::APIError

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

Overview

Raised when the API responds with a non-2xx status.

The mailfloss API returns errors in the envelope:

{ "error": { "code": "...", "message": "...", "type": "...", "request_id": "..." } }

When the body is not JSON (or not in that envelope) the error degrades gracefully: code becomes "unknown_error" and message falls back to the raw body / a generic message.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body: nil) ⇒ APIError

Returns a new instance of APIError.

Parameters:

  • status: (Integer)
  • body: (String, nil) (defaults to: nil)


21
22
23
24
25
26
27
28
# File 'lib/mailfloss/errors.rb', line 21

def initialize(status:, body: nil)
  @status = status
  parsed = parse_error(body)
  @code = parsed[:code]
  @type = parsed[:type]
  @request_id = parsed[:request_id]
  super(parsed[:message])
end

Instance Attribute Details

#codeString (readonly)

Returns the value of attribute code.

Returns:

  • (String)


19
20
21
# File 'lib/mailfloss/errors.rb', line 19

def code
  @code
end

#request_idString? (readonly)

Returns the value of attribute request_id.

Returns:

  • (String, nil)


19
20
21
# File 'lib/mailfloss/errors.rb', line 19

def request_id
  @request_id
end

#statusInteger (readonly)

Returns the value of attribute status.

Returns:

  • (Integer)


19
20
21
# File 'lib/mailfloss/errors.rb', line 19

def status
  @status
end

#typeString? (readonly)

Returns the value of attribute type.

Returns:

  • (String, nil)


19
20
21
# File 'lib/mailfloss/errors.rb', line 19

def type
  @type
end