mirror of
				https://github.com/songquanpeng/one-api.git
				synced 2025-10-31 05:43:42 +08:00 
			
		
		
		
	fix: resp body when error
This commit is contained in:
		| @@ -181,16 +181,14 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { | ||||
| 		return errorWrapper(err, "do_request_failed", http.StatusInternalServerError) | ||||
| 	} | ||||
| 	if resp.StatusCode != http.StatusOK { | ||||
| 		// Print Data if Error | ||||
| 		bodyBytes, err := io.ReadAll(resp.Body) | ||||
| 		if err != nil { | ||||
| 			return errorWrapper(err, "read_response_body_failed", http.StatusInternalServerError) | ||||
| 		// Print the body in string | ||||
| 		if resp.Body != nil { | ||||
| 			buf := new(bytes.Buffer) | ||||
| 			buf.ReadFrom(resp.Body) | ||||
| 			log.Printf("Error Channel (%s): %s", baseURL, buf.String()) | ||||
| 			return errorWrapper(err, "request_failed", resp.StatusCode) | ||||
| 		} | ||||
|  | ||||
| 		bodyString := string(bodyBytes) | ||||
|  | ||||
| 		log.Printf("Error: %s", bodyString) | ||||
|  | ||||
| 		return errorWrapper(err, "request_failed", resp.StatusCode) | ||||
| 	} | ||||
| 	err = req.Body.Close() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user