1.1.0 • Published 1 year ago

try-catch-ts v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Try catch ts

With try-catch-ts you can wrap any function with a try...catch statement functionally. If function runs without errors, it will return the data, otherwise the error will be returned.

Installation

npm i try-catch-ts

Usage

import { tryFn, isErroneous } from "try-catch-ts";

const main = async () => {
    const result = await tryFn(() => axios.get("https://pokeapi.co/api/v2/pokemon/ditto"));
    
    if (isErroneous(result)) {
        console.error(result.err);
        
        return;
    }
    
    const { val } = result;
}
import { tryFn, isSuccessful } from "try-catch-ts";

const getPokemon = async () => {
    const result = await tryFn(() => axios.get("https://pokeapi.co/api/v2/pokemon/ditto"));
    
    if (isSuccessful(result)) {
        return result.val;
    }
    
    // do something with error
    const { err } = result;
}

License

MIT

1.1.0

1 year ago

1.0.2

1 year ago

1.0.0

1 year ago