Exception: Mailkube::APIError

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

Overview

Raised for any non-2xx response, carrying the API's error envelope.

Rescue a subclass to branch on the category, and read the attributes for the detail. The envelope's name stays a plain string, so a value this release has never heard of is reported verbatim rather than coerced.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, error_name: "", status_code: 0, body: {}, retry_after: nil, request_id: nil) ⇒ APIError

There is deliberately one base constructor taking the whole envelope, and no subclass overrides it. Eight subclasses each repeating an argument list is how a duplication gate starts failing and how two categories start reporting different fields.



42
43
44
45
46
47
48
49
# File 'lib/mailkube/errors.rb', line 42

def initialize(message = nil, error_name: "", status_code: 0, body: {}, retry_after: nil, request_id: nil)
  super(message || (error_name.empty? ? "HTTP #{status_code}" : error_name))
  @error_name = error_name
  @status_code = status_code
  @body = body
  @retry_after = retry_after
  @request_id = request_id
end

Instance Attribute Details

#bodyHash (readonly)

Returns the decoded response body, or an empty hash.

Returns:

  • (Hash)

    the decoded response body, or an empty hash.



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

def body
  @body
end

#error_nameString (readonly)

Returns the machine-readable name from the envelope, e.g. quota_exceeded.

Returns:

  • (String)

    the machine-readable name from the envelope, e.g. quota_exceeded.



29
30
31
# File 'lib/mailkube/errors.rb', line 29

def error_name
  @error_name
end

#request_idString? (readonly)

Returns the server's request id, to quote to support.

Returns:

  • (String, nil)

    the server's request id, to quote to support.



37
38
39
# File 'lib/mailkube/errors.rb', line 37

def request_id
  @request_id
end

#retry_afterInteger? (readonly)

Returns the Retry-After header in seconds, when the server sent one.

Returns:

  • (Integer, nil)

    the Retry-After header in seconds, when the server sent one.



35
36
37
# File 'lib/mailkube/errors.rb', line 35

def retry_after
  @retry_after
end

#status_codeInteger (readonly)

Returns the HTTP status code.

Returns:

  • (Integer)

    the HTTP status code.



31
32
33
# File 'lib/mailkube/errors.rb', line 31

def status_code
  @status_code
end