export class ApiError extends Error {
  constructor(message: string) {
    super(message);
    this.name = "ApiError";
  }
}

export class ApiHttpError extends ApiError {
  readonly status: number;
  readonly body?: unknown;

  constructor(message: string, status: number, body?: unknown) {
    super(message);
    this.name = "ApiHttpError";
    this.status = status;
    this.body = body;
  }
}

export class ApiTimeoutError extends ApiError {
  readonly timeoutMs: number;

  constructor(timeoutMs: number) {
    super(`Request timed out after ${timeoutMs}ms`);
    this.name = "ApiTimeoutError";
    this.timeoutMs = timeoutMs;
  }
}

export class ApiNetworkError extends ApiError {
  override readonly cause?: Error | undefined;

  constructor(cause?: Error) {
    super(cause ? `Network error: ${cause.message}` : "Network error");
    this.name = "ApiNetworkError";
    this.cause = cause;
  }
}
