import BackErrorConstruct from "../main/definitions/backErrorConstruct"; export interface DryBackError { /** * Name */ n: string; /** * Group */ g?: string; /** * Type */ t: string; /** * Description */ d?: string; /** * Custom */ c: 0 | 1; /** * Info */ i?: Record; } export default class BackError extends Error { /** * @description * The name of the BackError. * @default BackError */ name: string; /** * @description * The group of the BackError. * Multiple errors can belong to a group. * @default undefined */ group: string | undefined; /** * @description * The description of the BackError. * Contains a more detailed message about the error. * It will only be sent when it is activated. * @default undefined */ readonly description: string | undefined; /** * @description * The type of the BackError. * The error type is a very abstract topic name. * Like validation error, database error, input error. * Some default types can be found in the Enum: ErrorType. * @default ErrorType.NormalError */ type: string; /** * @description * Indicates if the info of the BackError should also be transmitted to the client. * The BackError info is a dynamic object which contains more detailed information. * For example, with an valueNotMatchesWithMinLength error, * the info object could include what the length of the input is and * what the minimum length is. * @default true */ sendInfo: boolean; /** * @description * The BackError info. * The BackError info is a dynamic object which contains more detailed information. * For example, with an valueNotMatchesWithMinLength error, * the info object could include what the length of the input is and * what the minimum length is. * @default {} */ info: Record; /** * @description * Indicates if the BackError is private. * A private BackError only sends its type and * whether it is a custom-defined error. * @default false */ private: boolean; /** * @description * Indicates if the BackError is a custom-defined error. * @default true */ custom: boolean; /** * @description * Creates a BackError (An error that goes back to the client). * The error can be thrown and will be returned to the client. * You also can collect more BackErrors in a BackErrorBag and throw them together. * @example * new BackError('ValueNotMatchesWithMinLength',{minLength: 5, inputLength: 3}).throw(); * @param name * Name of the BackError * @param info * The BackError info is a dynamic object which contains more detailed information. * For example, with an valueNotMatchesWithMinLength error, * the info object could include what the length of the input is and * what the minimum length is. */ constructor(name: string, info?: Record); /** * @description * Creates a BackError (An error that goes back to the client). * The error can be thrown and will be returned to the client. * You also can collect more BackErrors in a BackErrorBag and throw them together. * @example * new BackError({name: 'ValueNotMatchesWithMinLength'},{minLength: 5, inputLength: 3}).throw(); * @param backErrorConstruct * The construct that will be used to create the BackError. * @param info * The BackError info is a dynamic object which contains more detailed information. * For example, with an valueNotMatchesWithMinLength error, * the info object could include what the length of the input is and * what the minimum length is. */ constructor(backErrorConstruct?: BackErrorConstruct, info?: Record); /** * @description * Returns the complete information as a string. */ toString(): string; /** * @description * Throws this BackError. * Alternative for throwing the BackError directly in a controller method. */ throw(): void; }