From ed427d03ff8eed67a8fabc3f79772a2ddf2f740e Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Sun, 15 Sep 2024 18:23:37 +0800 Subject: [PATCH] Simplify error handling in chatStreamGemini by removing unnecessary JSON unmarshaling and directly logging the error line. --- api/chat_main_handler.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/api/chat_main_handler.go b/api/chat_main_handler.go index 9d2cd93b..fd148f84 100644 --- a/api/chat_main_handler.go +++ b/api/chat_main_handler.go @@ -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 } }