All files / app/common/error CustomError.ts

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 4780x               10x 10x 10x 10x             10x   10x 10x         10x 10x 10x 10x 10x           80x 3x 3x 3x   3x 3x 3x   80x  
export default class CustomError extends Error {
    static shouldReport: boolean;
 
    data: any;
    title: any;
    type: string;
 
    constructor({
        data = {},
        message = '',
        title = '',
        name = '',
    }: {
        data?: any;
        message?: string;
        title?: string;
        name?: string;
    }) {
        super();
 
        Eif (typeof Error.captureStackTrace === 'function') {
            Error.captureStackTrace(this, CustomError);
        } else {
            this.stack = (new Error()).stack;
        }
 
        this.data = data;
        this.message = message;
        this.name = name;
        this.title = title;
        this.type = 'custom';
    }
 
    // todo: remove these methods when all error types has specific subclasses.
    // they are only provided for compatibility with errors defined in `app.errors.ts` while we transition
    // to proper error subclasses.
    protected setDefaultValues({
        name,
        defaultError,
        defaultTitle,
    }: { name: string; defaultError: string; defaultTitle: string}): void {
        this.name = this.name || name;
        this.message = this.message || defaultError;
        this.title = this.title || defaultTitle;
    }
}