A structured error returned by all terminusdb_ex operations.
Public API functions return {:error, %TerminusDB.Error{}} on failure; the
!/1-suffixed variants raise this same struct (it implements the Exception
behaviour). The :reason field classifies the failure so callers can pattern match
without inspecting HTTP status:
:reason | Meaning |
|---|---|
:transport | Network/transport failure (connection, timeout, …) |
:http | Non-2xx response with a non-JSON or unstructured body |
:api | TerminusDB API error (structured api:* JSON body) |
:decode | Response body could not be decoded as JSON |
Examples
iex> error = TerminusDB.Error.api(400, %{
...> "@type" => "api:DbCreateErrorResponse",
...> "api:error" => %{"@type" => "api:DatabaseAlreadyExists"},
...> "api:message" => "Database already exists.",
...> "api:status" => "api:failure"
...> })
iex> error.reason
:api
iex> error.api_type
"api:DatabaseAlreadyExists"
iex> Exception.message(error)
"TerminusDB API error 400 (api:DatabaseAlreadyExists): Database already exists."
Summary
Functions
Builds an :api error from a TerminusDB structured error body.
Builds a :decode error when the response body cannot be parsed as JSON.
Builds an :http error from a non-2xx status with an unstructured body.
Builds a :transport error from an underlying exception (e.g. Req.TransportError).
Types
@type reason() :: :transport | :http | :api | :decode
@type t() :: %TerminusDB.Error{ __exception__: term(), api_error: map() | nil, api_type: String.t() | nil, body: term(), cause: Exception.t() | nil, message: String.t(), reason: reason(), status: pos_integer() | nil }
Functions
@spec api(pos_integer(), map()) :: t()
Builds an :api error from a TerminusDB structured error body.
TerminusDB returns JSON of the shape
{"@type": "api:*ErrorResponse", "api:error": {...}, "api:message": "...", "api:status": "api:failure"}.
The @type inside api:error (if present) is surfaced as api_type for easy
pattern matching, e.g. "api:DatabaseAlreadyExists".
@spec decode(Exception.t(), binary() | nil) :: t()
Builds a :decode error when the response body cannot be parsed as JSON.
@spec http(pos_integer(), term()) :: t()
Builds an :http error from a non-2xx status with an unstructured body.
@spec transport(Exception.t()) :: t()
Builds a :transport error from an underlying exception (e.g. Req.TransportError).