Exception: PostmarkClient::ApiError

Inherits:
Error
  • Object
show all
Defined in:
lib/postmark_client/errors.rb

Overview

Raised when the Postmark API returns an error response

Examples:

Handling API errors

begin
  client.send_email(email)
rescue PostmarkClient::ApiError => e
  puts "Error #{e.error_code}: #{e.message}"
  puts "Response: #{e.response}"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, error_code: nil, response: nil) ⇒ ApiError

Initialize a new API error

Parameters:

  • message (String)

    the error message

  • error_code (Integer, String, nil) (defaults to: nil)

    the Postmark error code

  • response (Hash, nil) (defaults to: nil)

    the full response body



40
41
42
43
44
# File 'lib/postmark_client/errors.rb', line 40

def initialize(message, error_code: nil, response: nil)
  @error_code = error_code
  @response = response
  super(message)
end

Instance Attribute Details

#error_codeInteger, ... (readonly)

Returns the Postmark error code.

Returns:

  • (Integer, String, nil)

    the Postmark error code



30
31
32
# File 'lib/postmark_client/errors.rb', line 30

def error_code
  @error_code
end

#responseHash? (readonly)

Returns the full error response body.

Returns:

  • (Hash, nil)

    the full error response body



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

def response
  @response
end