Conversation
There was a problem hiding this comment.
Code Review
This pull request increases the default Gemini request timeout to 5 minutes and introduces a check in the proxy engine to return a 502 error when the upstream API returns empty candidates. The review feedback identifies that the new validation logic has inconsistent indentation, uses unsafe type casting, and fails to account for nested response structures handled elsewhere in the codebase.
| final candidates = payload['candidates'] as List?; | ||
| if (candidates != null && candidates.isEmpty) { | ||
| return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates'); | ||
| } |
There was a problem hiding this comment.
The indentation of the added lines is inconsistent with the rest of the file (which uses 2 spaces). Additionally, the check for candidates is incomplete as it doesn't account for potential nesting under a response key, which is handled elsewhere in the codebase (e.g., in OpenAiResponseMapper). Using is List instead of a cast is also safer to avoid potential TypeError if the upstream returns an unexpected type. According to the Dart style guide, indentation should be 2 spaces.
| final candidates = payload['candidates'] as List?; | |
| if (candidates != null && candidates.isEmpty) { | |
| return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates'); | |
| } | |
| final response = (payload['response'] as Map?)?.cast<String, Object?>() ?? payload; | |
| final candidates = response['candidates']; | |
| if (candidates is List && candidates.isEmpty) { | |
| return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates'); | |
| } |
References
- Dart style guide specifies using 2 spaces for indentation. (link)
| final candidates = payload['candidates'] as List?; | ||
| if (candidates != null && candidates.isEmpty) { | ||
| return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates'); | ||
| } |
There was a problem hiding this comment.
The indentation of the added lines is inconsistent with the rest of the file (which uses 2 spaces). Additionally, the check for candidates is incomplete as it doesn't account for potential nesting under a response key, which is handled elsewhere in the codebase (e.g., in OpenAiResponseMapper). Using is List instead of a cast is also safer to avoid potential TypeError if the upstream returns an unexpected type. According to the Dart style guide, indentation should be 2 spaces.
| final candidates = payload['candidates'] as List?; | |
| if (candidates != null && candidates.isEmpty) { | |
| return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates'); | |
| } | |
| final response = (payload['response'] as Map?)?.cast<String, Object?>() ?? payload; | |
| final candidates = response['candidates']; | |
| if (candidates is List && candidates.isEmpty) { | |
| return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates'); | |
| } |
References
- Dart style guide specifies using 2 spaces for indentation. (link)
No description provided.