DoubleEntryLedger.Workers.CommandWorker.TransactionCommandMapResponseHandler (double_entry_ledger v0.4.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 for functions that operate on a TransactionCommandMap.
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.TransactionCommandMap.t() ) :: DoubleEntryLedger.Workers.CommandWorker.success_tuple() | {:error, Ecto.Changeset.t(DoubleEntryLedger.Command.TransactionCommandMap.t()) | String.t()}
Default response handler for functions that operate on a TransactionCommandMap.
Returns:
{:ok, transaction, event}on success{:error, changeset}when either the event or transaction changeset fails, with errors mapped onto an event map changeset{: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.
Handles errors that occur during transaction map conversion.
Schedules a retry for the given occable item, marking it as failed.
Parameters
occable_item: The event map 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.