Skip to content

fix: empty response#23

Open
goddammit1 wants to merge 1 commit intomxnix:mainfrom
goddammit1:fix-empty-response
Open

fix: empty response#23
goddammit1 wants to merge 1 commit intomxnix:mainfrom
goddammit1:fix-empty-response

Conversation

@goddammit1
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +473 to +476
final candidates = payload['candidates'] as List?;
if (candidates != null && candidates.isEmpty) {
return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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
  1. Dart style guide specifies using 2 spaces for indentation. (link)

Comment on lines +674 to +677
final candidates = payload['candidates'] as List?;
if (candidates != null && candidates.isEmpty) {
return _errorResponse(502, 'bad_gateway', 'Upstream API returned empty candidates');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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
  1. Dart style guide specifies using 2 spaces for indentation. (link)

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.

1 participant