class DuffelAPI::Errors::Error

Attributes

error[R]

Public Class Methods

new(error, response = nil) click to toggle source

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]

Calls superclass method
# 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

api_response() click to toggle source

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
code() click to toggle source

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
documentation_url() click to toggle source

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
message() click to toggle source

Return the message associated with the error

@return [String]

# File lib/duffel_api/errors/error.rb, line 46
def message
  @error["message"]
end
request_id() click to toggle source

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
source() click to toggle source

Return s the source of the error.

@return [Hash, nil]

# File lib/duffel_api/errors/error.rb, line 85
def source
  @error["source"]
end
title() click to toggle source

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
to_s() click to toggle source

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
type() click to toggle source

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