safeChain()
safeChain<
In,Out>(...handlers): (input) =>Result<Out,Error>
Creates a safe chain that catches errors and returns a zygos Result.
Behaves like createChain, but wraps the execution in a try/catch.
DEPRECATED
Use Result.fromThrowable from @zygos/result/result instead.
import { Result } from "@zygos/result/result";
const chain = createChain(auth, validate, handle);
const safeRun = Result.fromThrowable(
(input: Request) => chain(input),
(e) => e instanceof Error ? e : new Error(String(e)),
);
const result = safeRun(request);
Type Parametersβ
In: Inβ
The request/input type
Out: Outβ
The response/output type
Parametersβ
handlers: ...Handler<In, Out>[]β
Ordered list of handlers
Returnsβ
A function returning Result<Out, Error>
See Alsoβ
Full explanation, examples and live demo
Sinceβ
2.4.0