"use strict";
class HttpError extends Error {
  constructor(opts) {
    super(opts.message ?? `HTTP Error ${opts.statusCode} `);
    Object.setPrototypeOf(this, HttpError.prototype);
    this.name = HttpError.prototype.constructor.name;
    this.cause = opts.cause;
    this.statusCode = opts.statusCode;
    this.url = opts.url;
    this.method = opts.method;
    this.message = opts.message ?? `HTTP Error ${opts.statusCode}`;
    this.data = opts.data;
    if (opts.cause instanceof Error && opts.cause.stack) {
      this.stack = opts.cause.stack;
    }
  }
  static fromRequest(request, response, parsedError) {
    return new HttpError({
      message: response.statusText,
      url: response.url,
      method: request.method,
      statusCode: response.status,
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore the data property is a custom one from ErrorWithCode
      data: parsedError.data
    });
  }
}
exports.HttpError = HttpError;
