import { AxiosError } from 'axios';

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

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