All files errors.ts

78.26% Statements 36/46
100% Branches 2/2
40% Functions 2/5
78.26% Lines 36/46

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 461x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 1x 1x 1x             1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 2x 2x 2x 2x 2x 1x 1x     1x
 
/**
 * @internal
 */
export const INTENTIONAL_ERROR = Symbol.for('org.webrpc.intentional-error');
 
/**
 * When Conduit is in safe exceptions mode (the default), only exceptions thrown via raise() will be directly conveyed
 * to the caller. Otherwise the exceptions will be replaced with an RPCInternalError before being thrown.
 * @param error 
 */
export function raise<T>(error: T): never { 
    error[INTENTIONAL_ERROR] = true;
    throw error; 
}
 
export class RPCError extends Error {
    constructor(details: { name?: string, message: string, stack: string }) {
        super();
        
        this.name = details.name ?? this.constructor.name;
        this.message = details.message;
        this.stack = details.stack;
    }
 
    readonly name: string;
    readonly message: string;
    readonly stack: string;
 
    [Symbol.for('nodejs.util.inspect.custom')]() {
        return this.stack;
    }
}
 
export class RPCInternalError extends Error {
    constructor() {
        super(`An internal error has occurred. Please consult the service's logs for more details.`);
 
        this.name = this.constructor.name;
        this.stack = `${this.constructor.name}: ${this.message}`;
    }
    
    [Symbol.for('nodejs.util.inspect.custom')]() {
        return this.stack;
    }
}