@chubbyts/chubbyts-throwable-to-error
Version:
It converts any throwable into an Error.
16 lines (15 loc) • 532 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.throwableToError = void 0;
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;
};
exports.throwableToError = throwableToError;