UNPKG

2.6 kBTypeScriptView Raw
1/// <reference types="node" resolution-mode="require"/>
2/**
3 * Standard error to use. This contains a key, status code and info object.
4 * Mostly provided to make it easier to return errors from your API's.
5 *
6 * @since 0.1.0
7 * @class
8 */
9export class AppError extends Error {
10 /**
11 * @param {*} value
12 * @returns {value is AppError}
13 */
14 static instanceOf(value: any): value is AppError;
15 /**
16 * @param {Record<string, any>} [info={}]
17 * @param {Error} [error]
18 * @returns {AppError}
19 */
20 static notFound(info?: Record<string, any> | undefined, error?: Error | undefined): AppError;
21 /**
22 * @param {Record<string, any>} [info={}]
23 * @param {Error} [error]
24 * @returns {AppError}
25 */
26 static notImplemented(info?: Record<string, any> | undefined, error?: Error | undefined): AppError;
27 /**
28 * @param {Record<string, any>} [info={}]
29 * @param {Error} [error]
30 * @returns {AppError}
31 */
32 static serverError(info?: Record<string, any> | undefined, error?: Error | undefined): AppError;
33 /**
34 * @param {string} key
35 * @param {Record<string, any>} [info={}]
36 * @param {Error} [error]
37 * @returns {AppError}
38 */
39 static validationError(key: string, info?: Record<string, any> | undefined, error?: Error | undefined): AppError;
40 /**
41 * Format any error skipping the stack automatically for nested errors
42 *
43 * @param {AppError | Error | undefined | null | {} | string | number | boolean |
44 * Function | unknown} [e]
45 * @returns {Record<string, any>}
46 */
47 static format(e?: AppError | Error | undefined | null | {} | string | number | boolean | Function | unknown): Record<string, any>;
48 /**
49 * @param {string} key
50 * @param {number} status
51 * @param {Record<string, any>} [info={}]
52 * @param {Error} [cause]
53 */
54 constructor(key: string, status: number, info?: Record<string, any> | undefined, cause?: Error | undefined);
55 key: string;
56 status: number;
57 info: Record<string, any>;
58 cause: Error | undefined;
59 /**
60 * Use AppError#format when AppError is passed to JSON.stringify().
61 * This is used in the compas insight logger in production mode.
62 */
63 toJSON(): Record<string, any>;
64 /**
65 * Use AppError#format when AppError is passed to console.log / console.error.
66 * This works because it uses `util.inspect` under the hood.
67 * Util#inspect checks if the Symbol `util.inspect.custom` is available.
68 */
69 [inspect.custom](): Record<string, any>;
70}
71import { inspect } from "node:util";