Skip to main content

Function: withUtilityErrorHandling()

withUtilityErrorHandling<T>(operation: () => Promise<T>, operationName: string, fallbackValue?: T, shouldThrow?: boolean): Promise<T>

Defined in: src/utils/errorHandling.ts:94

Simple error handling wrapper for utility functions. Provides consistent error logging and error response formatting.

Type Parametersโ€‹

Tโ€‹

T

Parametersโ€‹

operationโ€‹

() => Promise<T>

The async operation to execute

operationNameโ€‹

string

Name of the operation for logging

fallbackValue?โ€‹

T

Value to return if operation fails (required if shouldThrow is false)

shouldThrow?โ€‹

boolean = false

Whether to throw on error or return fallback value

Returnsโ€‹

Promise<T>

Promise resolving to operation result or fallback value

Throwsโ€‹

When shouldThrow is true or when shouldThrow is false but no fallbackValue is provided