-
Notifications
You must be signed in to change notification settings - Fork 5
DOCSP-55531: Add voyage api error handling #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOCSP-55531: Add voyage api error handling #50
Conversation
- Add custom error classes (VoyageAuthError, VoyageAPIError) to distinguish error types - Update generateVoyageEmbedding to throw VoyageAuthError for 401 responses - Return 401 status for authentication errors, 503 for API errors - Improve client-side error handling with user-friendly messages - Update tests to verify proper error handling for different scenarios
- Python FastAPI backend: - Created custom exception classes (VoyageAuthError, VoyageAPIError) - Created error response utility function - Added global exception handlers in main.py - Updated vector search endpoint to use custom exceptions - Returns 400 for missing API key (SERVICE_UNAVAILABLE) - Returns 401 for invalid API key (VOYAGE_AUTH_ERROR) - Returns 503 for Voyage AI API errors (VOYAGE_API_ERROR) - Updated test to match new error handling behavior - Java Spring backend: - Created custom exception classes (VoyageAuthException, VoyageAPIException, ServiceUnavailableException) - Updated GlobalExceptionHandler with handlers for new exceptions - Updated MovieServiceImpl to throw custom exceptions - Returns 400 for missing API key (SERVICE_UNAVAILABLE) - Returns 401 for invalid API key (VOYAGE_AUTH_ERROR) - Returns 503 for Voyage AI API errors (VOYAGE_API_ERROR) - Updated tests to expect ServiceUnavailableException instead of ValidationException All three backends (Express, Python, Java) now have consistent Voyage AI error handling.
Replace datetime.utcnow() with datetime.now(timezone.utc) to fix deprecation warning in Python 3.12+.
e4fa015 to
695161c
Compare
dacharyc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java and Node.js seem to work as expected, but I'm not getting the result I expect with the Python server.
- Remove accidentally added .python-version file - Update get_embedding() to catch specific voyageai.error exceptions: - AuthenticationError (401) -> VoyageAuthError - InvalidRequestError (400) -> VoyageAPIError - RateLimitError (429) -> VoyageAPIError - ServiceUnavailableError (503) -> VoyageAPIError - VoyageError (other) -> VoyageAPIError - Import VoyageAuthError and VoyageAPIError in tests for future use This fixes the issue where authentication errors were not being properly detected because the code was relying on string matching instead of catching the SDK's specific exception types.
dacharyc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not sure what I should be expecting for the Python app, but I'm not hitting the Voyage AI-specific errors.
The voyageai.Client() constructor can raise AuthenticationError if the API key is empty or invalid. Previously, this was happening outside the try/except block that catches Voyage AI exceptions, causing the error to be caught by the generic Exception handler and returned as a 500 error instead of a 401. This fix moves the client creation inside the try block so that AuthenticationError from the constructor is properly caught and converted to a VoyageAuthError with a 401 status code.
dacharyc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Now the Python server is behaving as expected. LGTM - thanks for the updates!
|
thanks for the thorough review @dacharyc |
Add custom error classes (VoyageAuthError, VoyageAPIError) to distinguish error types
Update generateVoyageEmbedding to throw VoyageAuthError for 401 responses
Return 401 status for authentication errors, 503 for API errors
Improve client-side error handling with user-friendly messages
Update tests to verify proper error handling for different scenarios