All files / src/error error.ts

100% Statements 55/55
100% Branches 2/2
100% Functions 2/2
100% Lines 55/55

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 561x 1x 1x 1x 1x 1x 1x 1x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x  
import { IHTTPError } from './error.inteface'
 
/**
 * Represents an error that can be thrown during interactions with the Hoyolab API.
 *
 * @class
 * @category Main
 */
export class HoyoAPIError extends Error {
  /**
   * The name of this error.
   */
  public readonly name: string
 
  /**
   * The message associated with this error.
   */
  public readonly message: string
 
  /**
   * The HTTP object
   */
  public readonly http?: IHTTPError
 
  /**
   * The error code
   */
  public readonly code?: number
 
  /**
   * Constructs a new instance of the HoyolabError class with the specified message.
   *
   * @param message The message to associate with this error.
   */
  constructor(message: string, code?: number, http?: IHTTPError) {
    super(message)
 
    /**
     * The name of this error.
     */
    this.name = this.constructor.name
 
    /**
     * The message associated with this error.
     */
    this.message = message
 
    this.code = code
 
    this.http = http
 
    // Capture the stack trace of this error instance.
    Error.captureStackTrace(this, this.constructor)
  }
}