Skip to main content

Function: withErrorHandling()

withErrorHandling<T>(operation: () => Promise<T>, storeOrContext: ErrorHandlingBackendContext | ErrorHandlingFrontendStore): Promise<T>

Defined in: shared/utils/errorHandling.ts:236

Handle async operations with frontend store or backend context integration.

Type Parametersโ€‹

Tโ€‹

T

The return type of the async operation

Parametersโ€‹

operationโ€‹

() => Promise<T>

Async operation to execute with error handling

storeOrContextโ€‹

Either frontend store with error/loading state management or backend context with logger

ErrorHandlingBackendContext | ErrorHandlingFrontendStore

Returnsโ€‹

Promise<T>

Promise resolving to operation result

Remarksโ€‹

  • For frontend stores: Automatically manages loading state and error state in the provided store. Clears error state before operation, sets loading during execution, and handles error state on failure while preserving the original error.
  • For backend contexts: Logs operation failures using the provided logger with contextual information. Preserves original error for upstream handling while ensuring proper logging.