PhoenixKitAI.Errors (PhoenixKitAI v0.2.1)

Copy Markdown View Source

Central mapping from error atoms (returned by the AI module's public API) to translated human-readable strings.

Keeping the API layer locale-agnostic means callers and integration consumers can pattern-match on atoms and decide their own presentation. Anything user-facing (flash messages, error banners) goes through message/1 which wraps each mapping in gettext/1 using the PhoenixKitWeb.Gettext backend.

Supported reason shapes

  • plain atoms — :endpoint_not_found, :invalid_api_key, etc.
  • tagged tuples — {:api_error, status}, {:connection_error, reason}, {:prompt_error, :not_found | :disabled | :missing_variables}
  • unknown reasons — rendered as "Unexpected error: <inspect>" via gettext so nothing ever silently surfaces a raw struct

Example

iex> PhoenixKitAI.Errors.message(:invalid_api_key)
"Invalid API key"

iex> PhoenixKitAI.Errors.message({:api_error, 503})
"API error: 503"

Summary

Functions

Translates an error reason (atom or tagged tuple) into a user-facing string via gettext.

Functions

message(reason)

@spec message(term()) :: String.t()

Translates an error reason (atom or tagged tuple) into a user-facing string via gettext.