Bazaar.Errors (Bazaar v0.3.0)

Copy Markdown View Source

Error documents for API responses.

UCP errors are the spec's error response: a ucp envelope with status: "error" and a list of messages. ACP errors are the ACP Error object with type, code and message. response/2 renders either from a changeset or an error reason.

Example

Bazaar.Errors.response(:not_found)
# => %{
#   "ucp" => %{"version" => "2026-08-25", "status" => "error"},
#   "messages" => [
#     %{"type" => "error", "code" => "not_found", "content" => "Resource not found",
#       "severity" => "unrecoverable"}
#   ]
# }

Bazaar.Errors.response(:not_found, protocol: :acp)
# => %{"type" => "invalid_request", "code" => "not_found", "message" => "Resource not found"}

Summary

Functions

Flattens a changeset's errors into %{"field" => "a.b", "message" => "..."} entries, with interpolated messages.

Renders an error document for a changeset or an error reason.

Functions

changeset_details(changeset)

Flattens a changeset's errors into %{"field" => "a.b", "message" => "..."} entries, with interpolated messages.

response(reason_or_changeset, opts \\ [])

Renders an error document for a changeset or an error reason.

Options

  • :protocol - :ucp (default) or :acp