Exception: DuffelAPI::Errors::Error
- Inherits:
-
StandardError
- Object
- StandardError
- DuffelAPI::Errors::Error
- Defined in:
- lib/duffel_api/errors/error.rb
Direct Known Subclasses
APIError, AirlineError, AuthenticationError, InvalidRequestError, InvalidStateError, RateLimitError, ValidationError
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
-
#api_response ⇒ APIResponse
Returns the raw API response where this error originated from.
-
#code ⇒ String?
Returns the code of the error.
-
#documentation_url ⇒ String?
Returns a URL where documentation about the error can be found.
-
#initialize(error, response = nil) ⇒ Error
constructor
Builds an error, which provides access to the raw response.
-
#message ⇒ String
Return the message associated with the error.
-
#request_id ⇒ String
Returns the request ID of the request that generated the error.
-
#source ⇒ Hash?
Return s the source of the error.
-
#title ⇒ String?
Returns the title associated with the error.
-
#to_s ⇒ String
Returns a string representation of the error, taken from its
#message. -
#type ⇒ String?
Returns the type of the error.
Constructor Details
#initialize(error, response = nil) ⇒ Error
Builds an error, which provides access to the raw response. In general, subclasses of this error (e.g. APIError) will be raised, apart from for unrecognised errors returned by the Duffel API or errors that don’t look like standardised Duffel API errors.
16 17 18 19 20 21 22 23 |
# File 'lib/duffel_api/errors/error.rb', line 16 def initialize(error, response = nil) raise ArgumentError, "Duffel errors expect a hash" unless error.is_a?(Hash) @error = error @response = response super(error) end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/duffel_api/errors/error.rb', line 6 def error @error end |
Instance Method Details
#api_response ⇒ APIResponse
Returns the raw API response where this error originated from
92 93 94 |
# File 'lib/duffel_api/errors/error.rb', line 92 def api_response APIResponse.new(@response) end |
#code ⇒ String?
Returns the code of the error. See the Duffel API reference for possible values. This can be nil for errors that don’t look like standardised Duffel errors (e.g. errors returned by the load balancer rather than the API itself).
71 72 73 |
# File 'lib/duffel_api/errors/error.rb', line 71 def code @error["code"] end |
#documentation_url ⇒ String?
Returns a URL where documentation about the error can be found. This can be nil for errors that don’t look like standardised Duffel errors (e.g. errors returned by the load balancer rather than the API itself).
30 31 32 |
# File 'lib/duffel_api/errors/error.rb', line 30 def documentation_url @error["documentation_url"] end |
#message ⇒ String
Return the message associated with the error
46 47 48 |
# File 'lib/duffel_api/errors/error.rb', line 46 def @error["message"] end |
#request_id ⇒ String
Returns the request ID of the request that generated the error.
78 79 80 |
# File 'lib/duffel_api/errors/error.rb', line 78 def request_id api_response.request_id end |
#source ⇒ Hash?
Return s the source of the error.
85 86 87 |
# File 'lib/duffel_api/errors/error.rb', line 85 def source @error["source"] end |
#title ⇒ String?
Returns the title associated with the error. This can be nil for errors that don’t look like standardised Duffel errors (e.g. errors returned by the load balancer rather than the API itself).
39 40 41 |
# File 'lib/duffel_api/errors/error.rb', line 39 def title @error["title"] end |
#to_s ⇒ String
Returns a string representation of the error, taken from its #message
53 54 55 |
# File 'lib/duffel_api/errors/error.rb', line 53 def to_s @error["message"] end |
#type ⇒ String?
Returns the type of the error. See the Duffel API reference for possible values. This can be nil for errors that don’t look like standardised Duffel errors (e.g. errors returned by the load balancer rather than the API itself).
62 63 64 |
# File 'lib/duffel_api/errors/error.rb', line 62 def type @error["type"] end |