@chubbyts/chubbyts-throwable-to-error
Version:
It converts any throwable into an Error.
12 lines (11 loc) • 382 B
JavaScript
export const throwableToError = (e) => {
if (e instanceof Error) {
return e;
}
const error = new Error(typeof e === 'object' ? `${JSON.stringify(e)}` : `${String(e)}`);
// eslint-disable-next-line functional/immutable-data
error.name = typeof e;
// eslint-disable-next-line functional/immutable-data
error.stack = undefined;
return error;
};