Skip to content

Conversation

@cbullinger
Copy link
Collaborator

@cbullinger cbullinger commented Dec 8, 2025

  • 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

    image
  • Update tests to verify proper error handling for different scenarios

@cbullinger cbullinger marked this pull request as ready for review December 9, 2025 18:03
- 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+.
@cbullinger cbullinger force-pushed the docsp-55531-voyage-api-error-handling branch from e4fa015 to 695161c Compare December 12, 2025 23:05
Copy link
Collaborator

@dacharyc dacharyc left a 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.
@cbullinger cbullinger requested a review from dacharyc December 15, 2025 20:54
Copy link
Collaborator

@dacharyc dacharyc left a 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.
Copy link
Collaborator

@dacharyc dacharyc left a 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!

@cbullinger
Copy link
Collaborator Author

thanks for the thorough review @dacharyc

@cbullinger cbullinger merged commit 35d46cf into development Dec 16, 2025
3 checks passed
@cbullinger cbullinger deleted the docsp-55531-voyage-api-error-handling branch December 16, 2025 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants