From 02a7b240c08f1b43463107afd178b0b7ec19b98a Mon Sep 17 00:00:00 2001 From: xqdoo00o Date: Sun, 2 Jun 2024 13:59:22 +0800 Subject: [PATCH] fix tts err handle --- handlers.go | 6 +++--- internal/chatgpt/request.go | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/handlers.go b/handlers.go index 33bf9d9..9e8db8e 100644 --- a/handlers.go +++ b/handlers.go @@ -259,9 +259,7 @@ func tts(c *gin.Context) { response, err := chatgpt.POSTconversation(translated_request, &secret, deviceId, chat_require.Token, arkoseToken, proofToken, proxy_url) if err != nil { - c.JSON(500, gin.H{ - "error": "error sending request", - }) + c.JSON(500, gin.H{"error": "error sending request"}) return } defer response.Body.Close() @@ -281,6 +279,8 @@ func tts(c *gin.Context) { data := chatgpt.GetTTS(&secret, deviceId, apiUrl, proxy_url) if data != nil { c.Data(200, ttsTypeMap[format], data) + } else { + c.JSON(500, gin.H{"error": "synthesize error"}) } chatgpt.RemoveConversation(&secret, deviceId, convId, proxy_url) } diff --git a/internal/chatgpt/request.go b/internal/chatgpt/request.go index a16b5c4..bea7b8e 100644 --- a/internal/chatgpt/request.go +++ b/internal/chatgpt/request.go @@ -593,6 +593,9 @@ func GetTTS(secret *tokens.Secret, deviceId string, url string, proxy string) [] return nil } defer response.Body.Close() + if response.StatusCode != http.StatusOK { + return nil + } blob, err := io.ReadAll(response.Body) if err != nil { return nil