DoubleEntryLedger.Workers.CommandWorker.TransactionCommandResponseHandler (double_entry_ledger v0.2.0)
View SourceSpecialized error handling for the event processing pipeline in the double-entry ledger system.
This module provides utilities for processing, transforming, and propagating errors that occur during event processing. It handles error mapping between different data structures (transactions, events, event maps) while maintaining detailed error context.
Key responsibilities:
- Transfer validation errors from event/transaction changesets to event map changesets
- Maintain error context and traceability for audit and troubleshooting
- Build structured error responses for client consumption and retry logic
Examples
# Map event validation errors to an event map changeset
iex> default_response_handler(
...> {:error, :new_command, event_changeset, %{}},
...> command_map,
...> "MyWorker"
...> )
{:error, %Ecto.Changeset{data: %DoubleEntryLedger.Command.TransactionCommandMap{}}}
# Map transaction validation errors to an event map changeset
iex> default_response_handler(
...> {:error, :transaction, trx_changeset, %{}},
...> command_map,
...> "MyWorker"
...> )
{:error, %Ecto.Changeset{data: %DoubleEntryLedger.Command.TransactionCommandMap{}}}
Summary
Functions
Default response handler when starting from a stored Command.
Handles the case when OCC retries are exhausted.
Handles errors that occur during transaction map conversion.
Types
@type logable() :: DoubleEntryLedger.Command.t() | DoubleEntryLedger.Command.AccountCommandMap.t() | DoubleEntryLedger.Command.TransactionCommandMap.t() | map()
Functions
@spec default_response_handler( {:ok, map()} | {:error, :atom, any(), map()}, DoubleEntryLedger.Command.t() ) :: DoubleEntryLedger.Workers.CommandWorker.success_tuple() | {:error, DoubleEntryLedger.Command.t() | Ecto.Changeset.t()}
Default response handler when starting from a stored Command.
Returns:
{:ok, transaction, event}on success{:error, event}when the event pipeline returns a structured failure- schedules a retry and returns
{:error, message}for other failures
@spec handle_occ_final_timeout(DoubleEntryLedger.Occ.Occable.t(), Ecto.Repo.t()) :: Ecto.Multi.t()
Handles the case when OCC retries are exhausted.
Schedules a retry for the given occable item, marking it as OCC timeout.
Parameters
occable_item: The event or event map being processed.repo: The Ecto repository (unused).
Returns
- An
Ecto.Multithat updates the event as dead letter or timed out.
@spec handle_transaction_map_error( DoubleEntryLedger.Command.t(), any(), Ecto.Repo.t() ) :: Ecto.Multi.t()
Handles errors that occur during transaction map conversion.
Marks the command_queue_item as dead_letter
Parameters
occable_item: The event being processed.error: The error encountered during transaction map conversion.repo: The Ecto repository (unused).
Returns
- An
Ecto.Multithat updates the event with error information.