Tink.Error exception (Tink v1.0.0)

Copy Markdown View Source

Structured error returned by all Tink API functions.

Fields

  • :status — HTTP status code (e.g. 401, 429). nil for network errors.
  • :code — Tink error code string (e.g. "AUTHENTICATION_ERROR", "NOT_FOUND")
  • :message — Human-readable error message
  • :request_id — Value of X-Tink-Request-ID response header — include this when reporting issues to Tink support
  • :details — Raw decoded response body for inspection

Common error codes (from Tink docs)

StatusCodeMeaning
400BAD_REQUESTMalformed request body or params
401AUTHENTICATION_ERRORMissing or invalid credentials
401UNAUTHORIZEDToken expired or revoked
403FORBIDDENMissing required scope
404NOT_FOUNDResource does not exist
409CONFLICTResource already exists
422UNPROCESSABLE_ENTITYValid request but business logic rejection
429TOO_MANY_REQUESTSRate limit exceeded
500INTERNAL_SERVER_ERRORTink server error
503SERVICE_UNAVAILABLETink service temporarily unavailable
nilNETWORK_ERRORConnection / timeout failure
nilDECODE_ERRORInvalid JSON in response body

Pattern matching

case Tink.Accounts.list(client) do
  {:ok, accounts}                                      -> handle(accounts)
  {:error, %Tink.Error{status: 401}}                  -> refresh_and_retry()
  {:error, %Tink.Error{status: 403, code: code}}      -> handle_missing_scope(code)
  {:error, %Tink.Error{status: 429}}                  -> back_off_and_retry()
  {:error, %Tink.Error{status: nil, code: "NETWORK_ERROR"}} -> handle_network_failure()
  {:error, %Tink.Error{request_id: rid} = err}        ->
    Logger.error("Tink error request_id=#{rid}: #{Exception.message(err)}")
end

Summary

Functions

Returns true if the error is an authentication/authorization error.

Build a JSON decode error.

Build a structured error from an HTTP response.

Build a network-level error (no HTTP response received).

Returns true if the resource was not found.

Returns true if the error is retryable (429, 503, or network failure).

Types

t()

@type t() :: %Tink.Error{
  __exception__: true,
  code: String.t() | nil,
  details: map() | nil,
  message: String.t(),
  request_id: String.t() | nil,
  status: non_neg_integer() | nil
}

Functions

auth_error?(arg1)

@spec auth_error?(t()) :: boolean()

Returns true if the error is an authentication/authorization error.

decode(reason)

@spec decode(String.t()) :: t()

Build a JSON decode error.

from_response(status, body, request_id \\ nil)

@spec from_response(non_neg_integer(), map(), String.t() | nil) :: t()

Build a structured error from an HTTP response.

Tries the following keys in order to find the error code: errorCode, error, code

Tries the following keys for the message: errorMessage, error_description, message

network(reason)

@spec network(String.t()) :: t()

Build a network-level error (no HTTP response received).

not_found?(arg1)

@spec not_found?(t()) :: boolean()

Returns true if the resource was not found.

retryable?(arg1)

@spec retryable?(t()) :: boolean()

Returns true if the error is retryable (429, 503, or network failure).