class DuffelAPI::Errors::Error
Attributes
Public Class Methods
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.
@param error [Hash] the parsed error data from the API @param response [APIResponse, nil] @return [Error]
# 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
Public Instance Methods
Returns the raw API response where this error originated from
@return [APIResponse]
# File lib/duffel_api/errors/error.rb, line 92 def api_response APIResponse.new(@response) end
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).
@return [String, nil]
# File lib/duffel_api/errors/error.rb, line 71 def code @error["code"] end
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).
@return [String, nil]
# File lib/duffel_api/errors/error.rb, line 30 def documentation_url @error["documentation_url"] end
Return the message associated with the error
@return [String]
# File lib/duffel_api/errors/error.rb, line 46 def message @error["message"] end
Returns the request ID of the request that generated the error.
@return [String]
# File lib/duffel_api/errors/error.rb, line 78 def request_id api_response.request_id end
Return s the source of the error.
@return [Hash, nil]
# File lib/duffel_api/errors/error.rb, line 85 def source @error["source"] end
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).
@return [String, nil]
# File lib/duffel_api/errors/error.rb, line 39 def title @error["title"] end
Returns a string representation of the error, taken from its ‘#message`
@return [String]
# File lib/duffel_api/errors/error.rb, line 53 def to_s @error["message"] end
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).
@return [String, nil]
# File lib/duffel_api/errors/error.rb, line 62 def type @error["type"] end