Signature
tsSignature
export function recover<I, O, O2, E, E2, C extends object>( source: Behavior<I, O, E, C>, handler: (error: E, input: I, context: TaskContext<C>) => Awaitable<Result<O2, E2>>,): Behavior<I, O | O2, E2, C>;Imports
tsImport
import { recover } from "@/lib/flow/recover";import { recover } from "@/lib/flow";Type Parameters
IInput type.
OSource output type.
O2Handler output type.
ESource domain error type.
E2Handler domain error type.
CCustom context type.
Parameters
handlerCallback invoked for source domain failures.
Returns
A behavior that can produce source output, handler output, or handler failure.
Return type
Behavior<I, O | O2, E2, C>Details
Runtime errors bypass the handler. The returned behavior replaces the source domain error type
with the handler error type.
Examples
tsExample
const loadWithFallback = recover(loadUser, (_error, _input, context) => context.ok({ id: "anonymous" }),);Related Symbols
Awaitable
Represents a value that may be returned directly or through a Promise.
type
Behavior
Executable Flow workflow unit.
type
input
Creates an identity behavior for starting typed pipelines.
function
Result
Explicit success-or-failure outcome used throughout Flow.
type
TaskContext
Runtime context provided to a `task` callback.
type
Source
tsflow/recover.ts:28-47
export function recover<I, O, O2, E, E2, C extends object>( source: Behavior<I, O, E, C>, handler: (error: E, input: I, context: TaskContext<C>) => Awaitable<Result<O2, E2>>,): Behavior<I, O | O2, E2, C> { return async (input, context) => { const result = await runBehavior(source, input, context);
if (result.ok) { return result; }
if (isRuntimeError(result.error)) { return err(result.error); }
return task((_input: I, taskContext: TaskContext<C>) => handler(result.error as E, input, taskContext), )(input, context); };}