All files / src/libs/chartkit-error chartkit-error.ts

66.66% Statements 6/9
50% Branches 3/6
50% Functions 1/2
66.66% Lines 6/9

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            3x                   2x             2x   2x   2x             3x      
export type ChartKitErrorArgs = {
    code?: number | string;
    originalError?: Error;
    message?: string;
};
 
export const CHARTKIT_ERROR_CODE = {
    NO_DATA: 'ERR.CK.NO_DATA',
    INVALID_DATA: 'ERR.CK.INVALID_DATA',
    UNKNOWN: 'ERR.CK.UNKNOWN_ERROR',
    UNKNOWN_PLUGIN: 'ERR.CK.UNKNOWN_PLUGIN',
    TOO_MANY_LINES: 'ERR.CK.TOO_MANY_LINES',
};
 
export class ChartKitError extends Error {
    readonly code: number | string;
    readonly isCustomError = true;
 
    constructor({
        originalError,
        message,
        code = CHARTKIT_ERROR_CODE.UNKNOWN,
    }: ChartKitErrorArgs = {}) {
        super(message);
 
        this.code = code;
 
        Iif (originalError) {
            this.name = originalError.name;
            this.stack = originalError.stack;
        }
    }
}
 
export const isChartKitError = (error: unknown): error is ChartKitError => {
    return error instanceof Error && 'isCustomError' in error;
};