Creates new custom Error constructor. Use it to create errors to throw.
D - details object interface
Create basic custom error
const MyError = createError("MyError");throw new MyError("My custom problem happened");
Create custom error with specified details shape
const HttpError = createError<{ code: number, url: string }>("HttpError");throw new HttpError("Not Found", { code: 404, url: "/image.gif" });
Create custom error defining parent error to inherit from
const HttpError = createError<{ code: number, url: string }>("HttpError");const NotFoundError = createError({ url: string }, HttpError);const err = new NotFoundError("Not Found", { url: "/image.gif" });err instanceof NotFoundError; // trueerr instanceof HttpError; // true
error name
Error to inherit from (built-in or custom error)
Optional
options to override global options
Generated using TypeDoc
Creates new custom Error constructor. Use it to create errors to throw.
Typeparam
D - details object interface
Example
Create basic custom error
Example
Create custom error with specified details shape
Example
Create custom error defining parent error to inherit from
Returns