An RFC 9457 problem document, and the one function that sends one.
Every problem response is built with new/2 from a response code in
LightningWeb.API.Codes and sent with respond/2 or halt/2, whoever
answers: LightningWeb.API.FallbackController, a plug, a webhook, or
LightningWeb.Endpoint after an exception.
Summary
Functions
The problem document respond/2 sends.
The content type a problem sent on conn takes: application/problem+json
when the request's Accept names it, in any position and whatever its q,
and application/json otherwise.
Sends problem as the response, as respond/2 does, and halts the plug
pipeline.
Builds the problem for a response code from LightningWeb.API.Codes.
Sends problem as the response.
Types
@type t() :: %LightningWeb.API.Problem{ code: LightningWeb.API.Codes.code(), errors: [LightningWeb.API.Errors.entry()], extensions: map(), headers: [{String.t(), String.t()}], status: pos_integer() }
Functions
The problem document respond/2 sends.
@spec content_type(Plug.Conn.t()) :: String.t()
The content type a problem sent on conn takes: application/problem+json
when the request's Accept names it, in any position and whatever its q,
and application/json otherwise.
@spec halt(Plug.Conn.t(), t()) :: Plug.Conn.t()
Sends problem as the response, as respond/2 does, and halts the plug
pipeline.
@spec new(LightningWeb.API.Codes.code(), keyword()) :: t()
Builds the problem for a response code from LightningWeb.API.Codes.
Options:
:errors- the entries, fromLightningWeb.API.Errors.:extensions- extra top-level members for this answer, such aswork_order_id.:headers- response headers that belong to the answer.:retry_after- seconds, sent asretry-after;nilsends none.:status- one ofLightningWeb.API.Codes.statuses/1forcodeother than its own, for a route that keeps a status of its own, such as 429 for every limiter refusal on/i/*.
@spec respond(Plug.Conn.t(), t()) :: Plug.Conn.t()
Sends problem as the response.
The body is the same whatever the request's Accept. The content type is
application/problem+json only when Accept names it, and
application/json otherwise.