Exception: Html2img::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Html2img::Error
- 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.
Direct Known Subclasses
AuthenticationError, ConnectionError, InsufficientCreditsError, NotFoundError, NotSubscribedError, RateLimitError, ServerError, TimeoutError, ValidationError
Instance Attribute Summary collapse
-
#error_code ⇒ String?
readonly
The machine-readable
codefrom the API body. -
#payload ⇒ Hash
readonly
The decoded JSON response body, when available.
-
#status_code ⇒ Integer?
readonly
The HTTP status, when the failure came from a response.
Instance Method Summary collapse
-
#initialize(message, status_code: nil, payload: {}, error_code: nil) ⇒ Error
constructor
A new instance of Error.
-
#to_s ⇒ Object
The message with the API's error code appended, when there is one.
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(, status_code: nil, payload: {}, error_code: nil) super() @status_code = status_code @payload = payload || {} @error_code = error_code end |
Instance Attribute Details
#error_code ⇒ String? (readonly)
Returns the machine-readable code from the API body.
15 16 17 |
# File 'lib/html2img/errors.rb', line 15 def error_code @error_code end |
#payload ⇒ Hash (readonly)
Returns the decoded JSON response body, when available.
18 19 20 |
# File 'lib/html2img/errors.rb', line 18 def payload @payload end |
#status_code ⇒ Integer? (readonly)
Returns 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_s ⇒ Object
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 |