Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

tryCatch

import { tryCatch } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/async_either.ts";

Wraps a Async of A in a try-catch block which upon failure returns B instead. Upon success returns a Right and Left for a failure.

@example
import * as TE from "./async_either.ts";
import * as E from "./either.ts";

const tryFetch = TE.tryCatch(
  fetch,
  (error, args) => ({ message: "Fetch Error", error, args })
);

const result1 = await tryFetch("blah")(); // Left(ErrorStruct)
const result2 = await tryFetch("https://deno.land/")(); // Right(*Deno Website*)
function tryCatch<AS extends unknown[], A, B>(fasr: (...as: AS) => A | PromiseLike<A>, onThrow: (e: unknown, as: AS) => B): (...as: AS) => AsyncEither<B, A>;
§
tryCatch<AS extends unknown[], A, B>(fasr: (...as: AS) => A | PromiseLike<A>, onThrow: (e: unknown, as: AS) => B): (...as: AS) => AsyncEither<B, A>
[src]

§Type Parameters

§
AS extends unknown[]
[src]

§Parameters

§
fasr: (...as: AS) => A | PromiseLike<A>
[src]
§
onThrow: (e: unknown, as: AS) => B
[src]

§Return Type

§
(...as: AS) => AsyncEither<B, A>
[src]