Static
asWraps an error in a custom error type.
The custom error type that extends Error.
The error to wrap.
The constructor of the error class to use.
Optional
message: string | ((errMsg: string) => string)The optional override message.
An instance of the custom error type with the original message and stack trace.
try {
// ...
} catch (err) {
throw ErrorCore.as(err, TypeError); // throws TypeError
throw ErrorCore.as(err, TypeError, 'custom message'); // throws TypeError with custom message
throw ErrorCore.as(err, TypeError, (errMsg) => `custom message: ${errMsg}`); // throws TypeError with custom message prefix
}
Static
assertStatic
cloneStatic
fromGet or create an error from the given value, if it's not an error, it will be wrapped in an UnknownError.
Error instance or error message.
Error instance.
Static
isStatic
withWraps an error in a custom error type using a callback function.
The custom error type that extends Error.
The original error or error message to wrap.
A function that takes an optional message and returns an instance of the custom error type.
An instance of the custom error type with the original message and stack trace.
Error core functions
Since
v1.0.0