3.0.0 • Published 9 months ago

try-catch-ts v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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;
};

License

MIT

3.0.0

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago