All files error.ts

89.18% Statements 66/74
90.9% Branches 10/11
88.88% Functions 8/9
89.18% Lines 66/74

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85    2x 50x 50x 50x   50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x   2x 24x   24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x   2x 16x 16x   16x 16x 16x 16x 16x 16x 16x 16x 13x 3x 16x 16x 16x 16x 16x 16x 16x   2x 10x   10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x   2x 2x                 2x  
import type { Route } from './route';
 
export class RouteError extends Error {
    public readonly code: string;
    public readonly to: Route;
    public readonly from: Route | null;
 
    constructor(
        message: string,
        code: string,
        to: Route,
        from: Route | null = null
    ) {
        super(message);
        this.name = 'RouteError';
        this.code = code;
        this.to = to;
        this.from = from;
    }
}
 
export class RouteTaskCancelledError extends RouteError {
    public readonly taskName: string;
 
    constructor(taskName: string, to: Route, from: Route | null = null) {
        super(
            `Route task "${taskName}" was cancelled`,
            'ROUTE_TASK_CANCELLED',
            to,
            from
        );
        this.name = 'RouteTaskCancelledError';
        this.taskName = taskName;
    }
}
 
export class RouteTaskExecutionError extends RouteError {
    public readonly taskName: string;
    public readonly originalError: Error;
 
    constructor(
        taskName: string,
        to: Route,
        from: Route | null = null,
        originalError?: unknown
    ) {
        const error =
            originalError instanceof Error
                ? originalError
                : new Error(String(originalError));
        const message = `Route task "${taskName}" failed${error.message ? `: ${error.message}` : ''}`;
        super(message, 'ROUTE_TASK_EXECUTION_ERROR', to, from);
        this.name = 'RouteTaskExecutionError';
        this.taskName = taskName;
        this.originalError = error;
    }
}
 
export class RouteNavigationAbortedError extends RouteError {
    public readonly taskName: string;
 
    constructor(taskName: string, to: Route, from: Route | null = null) {
        super(
            `Navigation was aborted by task "${taskName}"`,
            'ROUTE_NAVIGATION_ABORTED',
            to,
            from
        );
        this.name = 'RouteNavigationAbortedError';
        this.taskName = taskName;
    }
}
 
export class RouteSelfRedirectionError extends RouteError {
    constructor(fullPath: string, to: Route, from: Route | null = null) {
        super(
            `Detected a self-redirection to "${fullPath}". Aborting navigation.`,
            'ROUTE_SELF_REDIRECTION',
            to,
            from
        );
        this.name = 'RouteSelfRedirectionError';
    }
}