export class HttpError extends Error {
  constructor(
    public readonly status: number,
    message: string,
    public readonly code?: string,
  ) {
    super(message);
    this.name = "HttpError";
  }
}

export function badRequest(message: string, code?: string): HttpError {
  return new HttpError(400, message, code);
}

export function unauthorized(message = "غير مصرح"): HttpError {
  return new HttpError(401, message, "unauthorized");
}

export function forbidden(message = "ممنوع الوصول"): HttpError {
  return new HttpError(403, message, "forbidden");
}

export function notFound(message = "غير موجود"): HttpError {
  return new HttpError(404, message, "not_found");
}
