@spa-tools/utilities
normalizeError()
The normalizeError()
function normalizes any value to a type-safe Error
object, which
is super useful when you want to ensure that a value is an Error
object within a catch
block.
Usage
import { normalizeError } from '@spa-tools/utilities';
try {
Promise.reject('An error occurred');
} catch (error) {
const err = normalizeError(error);
console.error(err.message);
}
Arguments
Name | Type | Description |
---|---|---|
error | unknown | The error value to normalize |
Returns
Error
- The normalized error.