Skip to content

Commit

Permalink
fix tts err handle
Browse files Browse the repository at this point in the history
  • Loading branch information
xqdoo00o committed Jun 2, 2024
1 parent 34ac763 commit 02a7b24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
3 changes: 3 additions & 0 deletions internal/chatgpt/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 02a7b24

Please sign in to comment.