Alva.Error (Alva v0.1.0)

Copy Markdown View Source

Normalizes Ash errors into a standard format consumed by the Vue frontend.

Error types produced by format/2:

  • "not_found" - The requested resource was not found.
  • "validation" - One or more fields failed validation. Includes a fields map with field-name keys and string-array values.
  • "conflict" - A global (non-field) conflict error with a code key.
  • "forbidden" - The actor is not authorized for the action.
  • "unknown" - An unhandled error. In dev/test, includes details with the formatted stacktrace. In production, returns a generic message.

Configuration:

  • :alva, :expose_unknown_errors - Set to true to expose error details in production. Defaults to true in dev/test, false in prod.

Summary

Functions

Formats an Ash error into a standardized map for the frontend.

Functions

format(error, stacktrace \\ nil)

(since 0.1.0)
@spec format(Exception.t() | struct() | term(), list() | nil) :: map()

Formats an Ash error into a standardized map for the frontend.

Accepts any Ash error struct and returns a map with :type, :message, and optionally :fields or :details.