File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ package proxy
44import (
55 "bufio"
66 "bytes"
7+ "compress/gzip"
78 "context"
89 "encoding/json"
910 "fmt"
@@ -343,10 +344,26 @@ func (ps *ProxyServer) executeRequestWithRetry(c *gin.Context, startTime time.Ti
343344
344345 // Read response body to get error information
345346 var errorMessage string
346- if bodyBytes , err := io .ReadAll (resp .Body ); err == nil {
347- errorMessage = string (bodyBytes )
347+ bodyBytes , err := io .ReadAll (resp .Body )
348+ if err != nil {
349+ errorMessage = fmt .Sprintf ("HTTP %d (failed to read body: %v)" , resp .StatusCode , err )
348350 } else {
349- errorMessage = fmt .Sprintf ("HTTP %d" , resp .StatusCode )
351+ if resp .Header .Get ("Content-Encoding" ) == "gzip" {
352+ reader , gErr := gzip .NewReader (bytes .NewReader (bodyBytes ))
353+ if gErr != nil {
354+ errorMessage = fmt .Sprintf ("gzip reader error: %v" , gErr )
355+ } else {
356+ uncompressedBytes , rErr := io .ReadAll (reader )
357+ reader .Close ()
358+ if rErr != nil {
359+ errorMessage = fmt .Sprintf ("gzip read error: %v" , rErr )
360+ } else {
361+ errorMessage = string (uncompressedBytes )
362+ }
363+ }
364+ } else {
365+ errorMessage = string (bodyBytes )
366+ }
350367 }
351368
352369 var jsonError struct {
You can’t perform that action at this time.
0 commit comments