Ensures that the provided value is an Error instance.
Error
The value to ensure is an Error.
A normalized Error instance.
This function is a convenience wrapper around normalizeError. It converts any thrown value into a proper Error object.
normalizeError
try { throw { message: 'Something went wrong' };} catch (err) { const error = ensureError(err); console.log(error.message); // 'Something went wrong' console.log(error.cause); // { message: 'Something went wrong' }} Copy
try { throw { message: 'Something went wrong' };} catch (err) { const error = ensureError(err); console.log(error.message); // 'Something went wrong' console.log(error.cause); // { message: 'Something went wrong' }}
1.0
Ensures that the provided value is an
Errorinstance.