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