Signature
tsSignature
export function mapError<I, O, E, E2, C extends object>( source: Behavior<I, O, E, C>, mapper: (error: E, context: RuntimeContext<C>) => Awaitable<E2>,): Behavior<I, O, E2, C>;Imports
tsImport
import { mapError } from "@/lib/flow/map-error";import { mapError } from "@/lib/flow";Type Parameters
ISource input type.
OSource output type.
ESource domain error type.
E2Mapped domain error type.
CCustom context type.
Parameters
mapper(error: E, context: RuntimeContext<C>) => Awaitable<E2>
Callback invoked for source domain errors.
Returns
A behavior with the same output type and mapped domain error type.
Return type
Behavior<I, O, E2, C>Details
Successful results pass through unchanged. Runtime errors such as cancellation and thrown
exceptions bypass the mapper so only expected failures are transformed.
Examples
tsExample
const publicLoad = mapError(loadUser, (error) => ({ kind: "load-user", cause: error }));Related Symbols
Awaitable
Represents a value that may be returned directly or through a Promise.
type
Behavior
Executable Flow workflow unit.
type
RuntimeContext
Execution context passed to every behavior.
type
thrown
Re-exports core result helpers used by advanced record internals.
re-export
Source
tsflow/map-error.ts:24-41
export function mapError<I, O, E, E2, C extends object>( source: Behavior<I, O, E, C>, mapper: (error: E, context: RuntimeContext<C>) => Awaitable<E2>,): Behavior<I, O, 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 err(await mapper(result.error, context)); };}