PhoenixKitEcommerce.Errors (PhoenixKitEcommerce v0.1.6)

Copy Markdown View Source

Central mapping from the error atoms returned by the e-commerce module's context, importers, image services, and web layer 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 module's own PhoenixKitEcommerce.Gettext backend so the strings are extractable into priv/gettext.

Supported reason shapes

  • plain atoms — :not_found, :cart_empty, :product_not_found, etc.
  • strings — passed through unchanged (legacy / interpolated messages)
  • anything else — rendered as "Unexpected error: <inspect>" so nothing silently surfaces a raw struct

Example

iex> PhoenixKitEcommerce.Errors.message(:cart_empty)
"The cart is empty."

Summary

Functions

Translates an error reason (atom, string, or any term) into a user-facing string via gettext.

Types

error()

@type error() ::
  :all_downloads_failed
  | :all_urls_invalid
  | :already_migrated
  | :cart_already_converting
  | :cart_empty
  | :cart_not_active
  | :email_already_registered
  | :email_exists_confirmed
  | :empty_file
  | :file_not_found
  | :forbidden
  | :import_log_not_found
  | :invalid_csv_format
  | :invalid_host
  | :invalid_scheme
  | :missing_content_type
  | :missing_slug
  | :missing_title
  | :no_images
  | :no_images_downloaded
  | :no_shipping_method
  | :not_found
  | :payment_option_not_found
  | :product_not_found
  | :rate_limited
  | :redirect_loop
  | :server_error
  | :temp_file_missing
  | :timeout
  | :unknown_format

Functions

message(reason)

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

Translates an error reason (atom, string, or any term) into a user-facing string via gettext.