1.0.4 • Published 1 year ago

parse-base-error v1.0.4

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

parse-base-error

NPM Downloads

Install

yarn add parse-base-error
# or
npm i parse-base-error

Example

import { parseBaseError } from 'parse-base-error';

const foo = async () => {
    try {
        await Promise.reject(new Error('Hello world'));
    } catch (e) {
        throw parseBaseError(e, 'foo', { hello: 'world' });
    }
};
const bar = async () => {
    try {
        await foo();
    } catch (e) {
        const error = parseBaseError(e, 'bar', 'bar')
            .log(); // [ParsedBaseError 2022-11-28T13:11:54.942Z]->[foo]->[bar]: hello world [{"hello":"world"},"bar"]

        console.log(error.data); // [ { hello: 'world' }, 'bar' ]
    }
};

bar();

License

MIT