Supabase.Error behaviour (supabase_potion v0.6.1)
Represents and centralizes error responses within the Supabase ecosystem.
The Supabase.Error
struct is a unified way to handle error responses,
providing fields to represent key attributes of an error while remaining flexible
enough to accommodate custom implementations.
Fields
code
(atom): A semantic representation of the error code, e.g.,:not_found
or:unauthorized
.message
(String.t): A human-readable message describing the error.service
(Supabase.service()): The service from which the error originated (e.g.,:auth
,:storage
).metadata
(map): Additional information to provide context about the error, such as the request path, headers, or response body.
Example
%Supabase.Error{
code: :not_found,
message: "Resource Not Found",
service: :storage,
metadata: %{
path: "/api/resource",
req_body: %{},
resp_body: "Not found",
headers: [{"content-type", "application/json"}]
}
}
Custom Error Handling
Libraries or users may define custom error parsers by implementing the
Supabase.Error
behaviour's from/2
callback from the Supabase.ErrorParser
protocol.
This enables the transformation of ANY structure into meaningful errors
specific to their application domain.
Summary
Callbacks
Callback used on invoking the HTTP error parsed on a response (status >= 400)
Functions
Helper to just transform an atom code into a more human-friendly string
Helper function to construct the metadata fields for when building
an error from a HTTP response, based into the "context", aka Supabase.Request
.
Creates a new Supabase.Error
struct based on informed options
Types
@type t() :: %Supabase.Error{ code: atom(), message: String.t(), metadata: map(), service: Supabase.service() | nil }
Callbacks
Functions
Helper to just transform an atom code into a more human-friendly string
@spec make_default_http_metadata(Supabase.Fetcher.Request.t()) :: map()
Helper function to construct the metadata fields for when building
an error from a HTTP response, based into the "context", aka Supabase.Request
.
Creates a new Supabase.Error
struct based on informed options