Exception: Html2img::Error

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

Overview

Base type for every error raised by the client at request time.

Rescuing this single type is enough to handle any failure originating from the gem. No raw Net::HTTP exception is ever allowed to escape the public API. Invalid arguments are reported before any request is sent, as a plain ArgumentError.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status_code: nil, payload: {}, error_code: nil) ⇒ Error

Returns a new instance of Error.



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

def initialize(message, status_code: nil, payload: {}, error_code: nil)
  super(message)
  @status_code = status_code
  @payload = payload || {}
  @error_code = error_code
end

Instance Attribute Details

#error_codeString? (readonly)

Returns the machine-readable code from the API body.

Returns:

  • (String, nil)

    the machine-readable code from the API body



15
16
17
# File 'lib/html2img/errors.rb', line 15

def error_code
  @error_code
end

#payloadHash (readonly)

Returns the decoded JSON response body, when available.

Returns:

  • (Hash)

    the decoded JSON response body, when available



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

def payload
  @payload
end

#status_codeInteger? (readonly)

Returns the HTTP status, when the failure came from a response.

Returns:

  • (Integer, nil)

    the HTTP status, when the failure came from a response



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

def status_code
  @status_code
end

Instance Method Details

#to_sObject

The message with the API's error code appended, when there is one.



28
29
30
# File 'lib/html2img/errors.rb', line 28

def to_s
  error_code ? "#{super} (#{error_code})" : super
end