{"version":3,"file":"HttpError.mjs","sources":["../../src/http/HttpError.ts"],"sourcesContent":["/**\n * HTTP Error.\n *\n * `HttpError` is a type of error class who've been thrown by the remote HTTP server.\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport class HttpError extends Error {\n  /**\n   * @internal\n   */\n  private body_: any = NOT_YET;\n\n  /**\n   * Initializer Constructor.\n   *\n   * @param method Method of the HTTP request.\n   * @param path Path of the HTTP request.\n   * @param status Status code from the remote HTTP server.\n   * @param message Error message from the remote HTTP server.\n   */\n  public constructor(\n    public readonly method:\n      | \"GET\"\n      | \"DELETE\"\n      | \"POST\"\n      | \"PUT\"\n      | \"PATCH\"\n      | \"HEAD\",\n    public readonly path: string,\n    public readonly status: number,\n    public readonly headers: Record<string, string | string[]>,\n    message: string,\n  ) {\n    super(message);\n\n    // INHERITANCE POLYFILL\n    const proto: HttpError = new.target.prototype;\n    if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);\n    else (this as any).__proto__ = proto;\n  }\n\n  /**\n   * `HttpError` to JSON.\n   *\n   * When you call `JSON.stringify()` function on current `HttpError` instance,\n   * this `HttpError.toJSON()` method would be automatically called.\n   *\n   * Also, if response body from the remote HTTP server forms a JSON object,\n   * this `HttpError.toJSON()` method would be useful because it returns the\n   * parsed JSON object about the {@link message} property.\n   *\n   * @template T Expected type of the response body.\n   * @returns JSON object of the `HttpError`.\n   */\n  public toJSON<T>(): HttpError.IProps<T> {\n    if (this.body_ === NOT_YET)\n      try {\n        this.body_ = JSON.parse(this.message);\n      } catch {\n        this.body_ = this.message;\n      }\n    return {\n      method: this.method,\n      path: this.path,\n      status: this.status,\n      headers: this.headers,\n      message: this.body_,\n    };\n  }\n}\nexport namespace HttpError {\n  /**\n   * Returned type of {@link HttpError.toJSON} method.\n   */\n  export interface IProps<T> {\n    method: \"GET\" | \"DELETE\" | \"POST\" | \"PUT\" | \"PATCH\" | \"HEAD\";\n    path: string;\n    status: number;\n    headers: Record<string, string | string[]>;\n    message: T;\n  }\n}\n\nconst NOT_YET = {} as any;\n"],"names":["HttpError","Error","constructor","method","path","status","headers","message","super","this","body_","NOT_YET","proto","prototype","Object","setPrototypeOf","__proto__","toJSON","JSON","parse"],"mappings":"AAOM,MAAOA,kBAAkBC;IAc7B,WAAAC,CACkBC,QAOAC,MACAC,QACAC,SAChBC;QAEAC,MAAMD;QAZUE,KAAMN,SAANA;QAOAM,KAAIL,OAAJA;QACAK,KAAMJ,SAANA;QACAI,KAAOH,UAAPA;QApBVG,KAAKC,QAAQC;QA0BnB,MAAMC,mBAA8BC;QACpC,IAAIC,OAAOC,gBAAgBD,OAAOC,eAAeN,MAAMG,aACjDH,KAAaO,YAAYJ;;IAgB1B,MAAAK;QACL,IAAIR,KAAKC,UAAUC,SACjB;YACEF,KAAKC,QAAQQ,KAAKC,MAAMV,KAAKF;UAC7B;YACAE,KAAKC,QAAQD,KAAKF;;QAEtB,OAAO;YACLJ,QAAQM,KAAKN;YACbC,MAAMK,KAAKL;YACXC,QAAQI,KAAKJ;YACbC,SAASG,KAAKH;YACdC,SAASE,KAAKC;;;;;AAiBpB,MAAMC,UAAU,CAAS;;"}