All files / src/Errors LocalNodeErrors.ts

55.55% Statements 5/9
0% Branches 0/4
20% Functions 1/5
55.55% Lines 5/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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58            1x                   1x 1x 1x                                               1x                              
// SPDX-License-Identifier: Apache-2.0
 
/**
 * Class representing the local node errors.
 * @extends Error
 */
export class LocalNodeErrors extends Error {
    public message: string;
    public name: string;
  
    /**
     * Create a local node error.
     * @param {string} name - The name of the error.
     * @param {string} message - The message of the error.
     */
    constructor(name: string, message: string) {
      super();
      this.name = name;
      this.message = message;
    }
 
    /**
     * Check if the error is a connection error.
     * @returns {boolean} True if the error is a connection error, false otherwise.
     */
    public IS_CONNECTION_ERROR(): boolean {
        return this.name == "Connection Error";
    }
 
 
    /**
     * Check if the error is a client error.
     * @returns {boolean} True if the error is a client error, false otherwise.
     */
    public CLIENT_ERROR(): boolean {
        return this.name == "Client Error";
    }
}
 
/**
 * Object containing functions to create specific local node errors.
 */
export const Errors = {
    /**
     * Create a connection error.
     * @param {number} [port] - The port number.
     * @returns {LocalNodeErrors} The connection error.
     */
    CONNECTION_ERROR: (port?: number) => new LocalNodeErrors("Connection Error", `Something went wrong, while trying to connect ${port ? `to port ${port}` : `to local node`}`),
 
    /**
     * Create a client error.
     * @param {string} [msg] - The error message.
     * @returns {LocalNodeErrors} The client error.
     */
    CLEINT_ERROR: (msg?: string) => new LocalNodeErrors("Client Error", `Something went wrong, while trying to create SDK Client${msg ? `: ${msg}` : ``}`),
}