Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

try-catch-ts

futurizame11MIT4.0.0TypeScript support: included

Error as value try catch functional wrapper

trycatch, error, handling, error wrapper

readme

Try catch ts

Error as values, wrap your functions with functional try-catch blocks.

Installation

npm i try-catch-ts

Usage

const response = await tryFn<{ name: string }>(async () => {
  const result = await fetch("https://pokeapi.co/api/v2/pokemon/ditto");
  return await result.json();
});

if (!response.ok) {
  console.log(response.error.message);

  return;
}

console.log(response.data.name);

License

MIT