Marqeta.Error exception (marqeta v1.0.0)

Copy Markdown View Source

Structured error type returned by all Marqeta API functions.

Error types

TypeHTTP statusRetryable?
:validation_error400, 422No
:authentication_error401No
:authorization_error403No
:not_found404No
:conflict_error409No
:rate_limit_error429Yes
:server_error500+Yes
:network_errorYes
:timeout_errorYes
:decode_errorNo
:api_errorotherNo
:unknown_errorNo

Fields

  • :type — error type atom (see table above)
  • :message — human-readable error message
  • :http_status — HTTP status code (when applicable)
  • :error_code — Marqeta error code string (e.g. "400040")
  • :request_id — Marqeta request correlation ID from x-request-id header
  • :field_errors — list of field-level validation errors
  • :retryable? — whether this error is safe to retry
  • :raw — raw response body or original exception

Summary

Functions

Builds a Marqeta.Error from a network or transport exception.

Builds a Marqeta.Error from a parsed HTTP response.

Types

error_type()

@type error_type() ::
  :api_error
  | :authentication_error
  | :authorization_error
  | :conflict_error
  | :decode_error
  | :network_error
  | :not_found
  | :rate_limit_error
  | :server_error
  | :timeout_error
  | :unknown_error
  | :validation_error

field_error()

@type field_error() :: %{
  code: String.t() | nil,
  field: String.t(),
  message: String.t()
}

headers()

@type headers() ::
  [{String.t(), String.t()}]
  | %{required(String.t()) => String.t() | [String.t()]}

t()

@type t() :: %Marqeta.Error{
  __exception__: true,
  error_code: String.t() | nil,
  field_errors: [field_error()],
  http_status: non_neg_integer() | nil,
  message: String.t(),
  raw: term(),
  request_id: String.t() | nil,
  retryable?: boolean(),
  type: error_type()
}

Functions

from_exception(exception)

@spec from_exception(term()) :: t()

Builds a Marqeta.Error from a network or transport exception.

from_response(map)

@spec from_response(%{body: term(), headers: headers(), status: non_neg_integer()}) ::
  t()

Builds a Marqeta.Error from a parsed HTTP response.

headers may be a keyword list of {name, value} tuples (as returned by Finch / Req) or a map of name => value strings.