n8n/packages/workflow/src/errors/ensure-error.ts

10 lines
306 B
TypeScript

/** Ensures `error` is an `Error */
export function ensureError(error: unknown): Error {
return error instanceof Error
? error
: new Error('Error that was not an instance of Error was thrown', {
// We should never throw anything except something that derives from Error
cause: error,
});
}