Skip to content

Commit

Permalink
Simplify error handling in chatStreamGemini by removing unnecessary J…
Browse files Browse the repository at this point in the history
…SON unmarshaling and directly logging the error line.
  • Loading branch information
swuecho committed Sep 15, 2024
1 parent 22635cc commit ed427d0
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,18 +1484,11 @@ func (h *ChatHandler) chatStreamGemini(w http.ResponseWriter, chatSession sqlc_q
}
if err != nil {
// Create an instance of ErrorResponse
var errorResponse gemini.ErrorResponse

// Unmarshal the JSON string into the ErrorResponse struct
err := json.Unmarshal(line, &errorResponse)
if err != nil {
fmt.Println("Error unmarshaling JSON:", err)
}
if errors.Is(err, io.EOF) {
log.Printf("End of stream reached: %+v, %+v", err, errorResponse)
log.Printf("End of stream reached: %+v, %+v", err, line)
return answer, answer_id, false
} else {
log.Printf("Error while reading response: %+v, %+v", err, errorResponse)
log.Printf("Error while reading response: %+v, %+v", err, line)
return "", "", true
}
}
Expand Down

0 comments on commit ed427d0

Please sign in to comment.