Function: defaultActionExceptionHandler()
defaultActionExceptionHandler(
ex
):Err
<ThrownActionError
>
Defined in: packages/action/src/safe.ts:78
Default exception handler for safe actions that converts thrown exceptions into Error Results.
This handler catches any exceptions that occur during safe action execution and wraps them in a ThrownActionError, then returns them as an Err Result instead of re-throwing. This ensures that safe actions never throw exceptions and always return Results.
Parameters
ex
unknown
The exception that was thrown
Returns
An Err Result containing a ThrownActionError
Example
typescript
const result = await createSafeAction()
.do(() => {
throw new Error('Something went wrong');
});
if (isErr(result)) {
console.log(result.error); // ThrownActionError
}