diff options
| author | Taylor Mullen <[email protected]> | 2025-05-11 13:32:56 -0700 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-05-11 13:55:55 -0700 |
| commit | 2970f0a06c234d1cb2fafb2e02754973bd1fa26a (patch) | |
| tree | eb3b3a3986cf601bd6533fc4b2f2b1e3c5a69a0b /packages/cli/src/ui/hooks/useGeminiStream.ts | |
| parent | 4d5f0dc0809eacdf7c034302a5e8f36bc75ca4e1 (diff) | |
feat: Integrate centralized error reporting for API interactions
Implements robust error handling for Gemini API calls, integrating with the centralized error reporting system.
- API errors are now caught and reported to dedicated log files, providing detailed diagnostics without cluttering the user interface.
- A concise error message is surfaced to the user in the UI, indicating an API issue.
- Ensures any pending UI updates are processed before an API error is displayed.
This change improves our ability to diagnose API-related problems by capturing rich error context centrally, while maintaining a clean user experience.
Signed-off-by: Gemini <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/hooks/useGeminiStream.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/useGeminiStream.ts | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index dbcb4e64..7ab30463 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -323,6 +323,18 @@ export const useGeminiStream = ( ); setStreamingState(StreamingState.Idle); return; // Stop processing the stream + } else if (event.type === ServerGeminiEventType.Error) { + // Flush out existing pending history item. + if (pendingHistoryItemRef.current) { + addItem(pendingHistoryItemRef.current, userMessageTimestamp); + setPendingHistoryItem(null); + } + addItem( + { type: 'error', text: `[API Error: ${event.value.message}]` }, + userMessageTimestamp, + ); + setStreamingState(StreamingState.Idle); + // Allow stream to end naturally } } // End stream loop @@ -335,7 +347,6 @@ export const useGeminiStream = ( setStreamingState(StreamingState.Idle); } catch (error: unknown) { if (!isNodeError(error) || error.name !== 'AbortError') { - console.error('Error processing stream or executing tool:', error); addItem( { type: 'error', |
