Exception: DuffelAPI::Errors::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • error (Hash)

    the parsed error data from the API

  • response (APIResponse, nil) (defaults to: nil)

Raises:

  • (ArgumentError)


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

#errorObject (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_responseAPIResponse

Returns the raw API response where this error originated from

Returns:



92
93
94
# File 'lib/duffel_api/errors/error.rb', line 92

def api_response
  APIResponse.new(@response)
end

#codeString?

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).

Returns:

  • (String, nil)


71
72
73
# File 'lib/duffel_api/errors/error.rb', line 71

def code
  @error["code"]
end

#documentation_urlString?

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).

Returns:

  • (String, nil)


30
31
32
# File 'lib/duffel_api/errors/error.rb', line 30

def documentation_url
  @error["documentation_url"]
end

#messageString

Return the message associated with the error

Returns:

  • (String)


46
47
48
# File 'lib/duffel_api/errors/error.rb', line 46

def message
  @error["message"]
end

#request_idString

Returns the request ID of the request that generated the error.

Returns:

  • (String)


78
79
80
# File 'lib/duffel_api/errors/error.rb', line 78

def request_id
  api_response.request_id
end

#sourceHash?

Return s the source of the error.

Returns:

  • (Hash, nil)


85
86
87
# File 'lib/duffel_api/errors/error.rb', line 85

def source
  @error["source"]
end

#titleString?

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).

Returns:

  • (String, nil)


39
40
41
# File 'lib/duffel_api/errors/error.rb', line 39

def title
  @error["title"]
end

#to_sString

Returns a string representation of the error, taken from its #message

Returns:

  • (String)


53
54
55
# File 'lib/duffel_api/errors/error.rb', line 53

def to_s
  @error["message"]
end

#typeString?

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).

Returns:

  • (String, nil)


62
63
64
# File 'lib/duffel_api/errors/error.rb', line 62

def type
  @error["type"]
end