LightningWeb.API.Problem (Lightning v2.20.1)

Copy Markdown View Source

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

t()

@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

body(problem)

@spec body(t()) :: map()

The problem document respond/2 sends.

content_type(conn)

@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.

halt(conn, problem)

@spec halt(Plug.Conn.t(), t()) :: Plug.Conn.t()

Sends problem as the response, as respond/2 does, and halts the plug pipeline.

new(code, opts \\ [])

@spec new(LightningWeb.API.Codes.code(), keyword()) :: t()

Builds the problem for a response code from LightningWeb.API.Codes.

Options:

  • :errors - the entries, from LightningWeb.API.Errors.
  • :extensions - extra top-level members for this answer, such as work_order_id.
  • :headers - response headers that belong to the answer.
  • :retry_after - seconds, sent as retry-after; nil sends none.
  • :status - one of LightningWeb.API.Codes.statuses/1 for code other than its own, for a route that keeps a status of its own, such as 429 for every limiter refusal on /i/*.

respond(conn, problem)

@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.