try-catch-ts
v3.0.0
Published
Error as value try catch wrapper
Downloads
29
Maintainers
Readme
Try catch ts
Error as values, wrap your functions with functional try-catch blocks.
Installation
npm i try-catch-ts
Usage
import { tryFn } from "try-catch-ts";
const main = async () => {
const [ok, data, error] = await tryFn(() => axios.get("https://pokeapi.co/api/v2/pokemon/ditto"));
if (!ok) {
console.error(error);
return;
}
const { name } = data;
};
import { tryFn } from "try-catch-ts";
const getPokemon = async () => {
const [ok, data, error] = await tryFn(() => axios.get("https://pokeapi.co/api/v2/pokemon/ditto"));
if (ok) {
return data.name;
}
// do something with error
const { message } = error;
};