UNPKG

@chubbyts/chubbyts-throwable-to-error

Version:
12 lines (11 loc) 382 B
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; };