import { AxiosError } from 'axios';

export class VertexProviderError extends Error {
  constructor(message: string, public statusCode?: number, public response?: any) {
    super(message);
    this.name = 'VertexProviderError';
  }
}

export function handleVertexError(error: unknown): VertexProviderError {
  if (error instanceof VertexProviderError) {
    return error;
  }
  
  if (error instanceof AxiosError) {
    return new VertexProviderError(
      error.message,
      error.response?.status,
      error.response?.data
    );
  }
  
  return new VertexProviderError(String(error));
}