@compas/stdlib
Version:
All kinds of utility functions
76 lines (75 loc) • 2.6 kB
TypeScript
/**
* Standard error to use. This contains a key, status code and info object.
* Mostly provided to make it easier to return errors from your API's.
*
* @since 0.1.0
* @class
*/
export class AppError extends Error {
/**
* @this {void}
* @param {*} value
* @returns {value is AppError}
*/
static instanceOf(this: void, value: any): value is AppError;
/**
* @this {void}
* @param {Record<string, any>} [info={}]
* @param {unknown} [error]
* @returns {AppError}
*/
static notFound(this: void, info?: Record<string, any>, error?: unknown): AppError;
/**
* @this {void}
* @param {Record<string, any>} [info={}]
* @param {unknown} [error]
* @returns {AppError}
*/
static notImplemented(this: void, info?: Record<string, any>, error?: unknown): AppError;
/**
* @this {void}
* @param {Record<string, any>} [info={}]
* @param {unknown} [error]
* @returns {AppError}
*/
static serverError(this: void, info?: Record<string, any>, error?: unknown): AppError;
/**
* @this {void}
* @param {string} key
* @param {Record<string, any>} [info={}]
* @param {unknown} [error]
* @returns {AppError}
*/
static validationError(this: void, key: string, info?: Record<string, any>, error?: unknown): AppError;
/**
* Format any error skipping the stack automatically for nested errors
*
* @this {void}
* @param {AppError | Error | undefined | null | {} | string | number | boolean |
* Function | unknown} [e]
* @returns {Record<string, any>}
*/
static format(this: void, e?: AppError | Error | undefined | null | {} | string | number | boolean | Function | unknown): Record<string, any>;
/**
* @param {string} key
* @param {number} status
* @param {Record<string, any>} [info={}]
* @param {unknown} [cause]
*/
constructor(key: string, status: number, info?: Record<string, any>, cause?: unknown);
key: string;
status: number;
info: Record<string, any>;
/**
* Use AppError#format when AppError is passed to JSON.stringify().
* This is used in the compas insight logger in production mode.
*/
toJSON(): Record<string, any>;
/**
* Use AppError#format when AppError is passed to console.log / console.error.
* This works because it uses `util.inspect` under the hood.
* Util#inspect checks if the Symbol `util.inspect.custom` is available.
*/
[inspect.custom](): Record<string, any>;
}
import { inspect } from "node:util";