Travel.Error (travel v0.2.0)

Copy Markdown View Source

Represents an error response from the Duffel API.

Fields

  • :status - HTTP status code
  • :request_id - Unique request identifier from Duffel
  • :code - Error code string
  • :message - Human-readable error message
  • :title - Short error title
  • :type - Error type classification
  • :documentation_url - Link to relevant documentation

Summary

Functions

Parses an API error response into a Travel.Error struct.

Types

t()

@type t() :: %Travel.Error{
  code: String.t(),
  documentation_url: String.t(),
  message: String.t(),
  request_id: String.t(),
  status: integer(),
  title: String.t(),
  type: String.t()
}

Functions

from_response(body, status)

@spec from_response(map(), integer()) :: t()

Parses an API error response into a Travel.Error struct.

Examples

iex> body = %{
...>   "meta" => %{"request_id" => "req_123"},
...>   "errors" => [%{
...>         "code" => "invalid_request",
...>         "message" => "Invalid parameter",
...>         "title" => "Invalid Request",
...>         "type" => "validation_error",
...>         "documentation_url" => "https://duffel.com/docs/api/errors"
...>       }]
...> }
iex> Travel.Error.from_response(body, 400)
%Travel.Error{
  status: 400,
  request_id: "req_123",
  code: "invalid_request",
  message: "Invalid parameter",
  title: "Invalid Request",
  type: "validation_error",
  documentation_url: "https://duffel.com/docs/api/errors"
}