The type of the cause of the error, which can be any object or error.
Creates a new instance of the BasaltError class.
Optional
basaltErrorOptions: Readonly<BasaltErrorOptions<T>>The options for the Basalt error. (BasaltErrorOptions)
Readonly
causeThe cause of the error, typically used to store the original error or additional context.
Optional
stackStatic
stackThe maximum number of stack frames to capture.
Gets the date when the error was created.
The creation date of the error.
Gets the HTTP status code associated with the error.
The HTTP status code.
Gets the error key, which identifies the type of error.
The key associated with the error.
Gets the unique identifier of the error.
The UUID of the error.
Static
captureCreate .stack property on a target object
Optional
constructorOpt: FunctionCreates a .stack
property on targetObject
, which when accessed returns
a string representing the location in the code at which
Error.captureStackTrace()
was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`
The first line of the trace will be prefixed with
${myObject.name}: ${myObject.message}
.
The optional constructorOpt
argument accepts a function. If given, all frames
above constructorOpt
, including constructorOpt
, will be omitted from the
generated stack trace.
The constructorOpt
argument is useful for hiding implementation
details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();
Optional
constructorOpt: FunctionStatic
isCheck if a value is an instance of Error
The value to check
True if the value is an instance of Error, false otherwise
Static
prepare
A custom error class that extends the native Error class, providing additional properties such as a unique identifier, error key, HTTP status code, and cause.
Example
The following example demonstrates how to throw and catch a BasaltError.
Example
The following example demonstrates how to create a BasaltError with a custom cause type.