DoubleEntryLedger.Workers.CommandWorker.AccountCommandResponseHandler (double_entry_ledger v0.2.0)

View Source

Response handler for account-related event processing operations.

This module provides standardized response handling for Command processing operations, including success and error scenarios. It handles the translation of database transaction results into appropriate response formats and performs comprehensive logging for audit and debugging purposes.

Key Features

  • Response Translation: Converts Ecto.Multi transaction results into standardized responses
  • Error Mapping: Maps validation errors from Events and Accounts back to AccountCommandMap changesets
  • Comprehensive Logging: Provides detailed logging for success and failure scenarios

Usage

This module is typically used by CommandWorker modules that process Command structures, providing a consistent interface for handling transaction results.

Error Handling

The module handles several types of errors:

  • Command validation errors (mapped to event-level changeset errors)
  • Account validation errors (mapped to payload-level changeset errors)
  • Multi step failures (logged and returned as string errors)

Summary

Types

Error response containing either a changeset with validation errors or a string error message.

Complete response type for event processing operations.

Success response tuple containing the processed account and associated event.

Types

error_response()

@type error_response() ::
  {:error,
   DoubleEntryLedger.Command.t()
   | Ecto.Changeset.t(DoubleEntryLedger.Command.t())}

Error response containing either a changeset with validation errors or a string error message.

logable()

response()

@type response() :: success_tuple() | error_response()

Complete response type for event processing operations.

success_tuple()

@type success_tuple() ::
  {:ok, DoubleEntryLedger.Account.t(), DoubleEntryLedger.Command.t()}

Success response tuple containing the processed account and associated event.

Functions

default_response_handler(response, event)

@spec default_response_handler(
  {:ok,
   %{
     account: DoubleEntryLedger.Account.t(),
     command_success: DoubleEntryLedger.Command.t()
   }}
  | {:error, :atom, any(), map()},
  DoubleEntryLedger.Command.t()
) :: response()

Handles responses from account event processing operations.

error(message, logable, changeset)

@spec error(String.t(), logable(), any()) :: {:ok, String.t()}

info(message, logable, schema)

@spec info(String.t(), logable(), any()) :: {:ok, String.t()}

warn(message, logable)

@spec warn(String.t(), logable()) :: {:ok, String.t()}

warn(message, logable, changeset)

@spec warn(String.t(), logable(), any()) :: {:ok, String.t()}