fix(OpenAIRecorder): set default status code for in progress or canceled HTTP requests

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
This commit is contained in:
Dorin Geman 2025-08-26 17:49:46 +03:00
parent af4bb5194f
commit a13d77c153
No known key found for this signature in database
1 changed files with 5 additions and 1 deletions

View File

@ -143,7 +143,7 @@ func (r *OpenAIRecorder) NewResponseRecorder(w http.ResponseWriter) http.Respons
rc := &responseRecorder{ rc := &responseRecorder{
ResponseWriter: w, ResponseWriter: w,
body: &bytes.Buffer{}, body: &bytes.Buffer{},
statusCode: http.StatusOK, statusCode: 0,
} }
return rc return rc
} }
@ -153,6 +153,10 @@ func (r *OpenAIRecorder) RecordResponse(id, model string, rw http.ResponseWriter
responseBody := rr.body.String() responseBody := rr.body.String()
statusCode := rr.statusCode statusCode := rr.statusCode
if statusCode == 0 {
// No status code was written (request canceled or failed before response).
statusCode = http.StatusRequestTimeout
}
var response string var response string
if strings.Contains(responseBody, "data: ") { if strings.Contains(responseBody, "data: ") {