fix: log response body when parsed upstream error message is empty
When an upstream error response parses as valid JSON but yields no usable
error message (e.g. an aggregator gateway returning {"error":{"message":""}}),
RelayErrorHandler previously produced a bare "bad response status code N"
error with no trace of the original body, making the failure undiagnosable.
Log the body preview in that case, mirroring the existing behavior for
unparseable bodies.
This commit is contained in:
+7
-1
@@ -123,7 +123,13 @@ func RelayErrorHandler(ctx context.Context, resp *http.Response, showBodyWhenFai
|
||||
return
|
||||
}
|
||||
}
|
||||
newApiErr = types.NewOpenAIError(errors.New(errResponse.ToMessage()), types.ErrorCodeBadResponseStatusCode, resp.StatusCode)
|
||||
message := errResponse.ToMessage()
|
||||
if message == "" {
|
||||
// The body parsed as JSON but carried no usable error message; log the
|
||||
// raw body so the upstream failure remains diagnosable.
|
||||
logger.LogError(ctx, fmt.Sprintf("bad response status code %d with empty error message, body: %s", resp.StatusCode, responseBodyPreview))
|
||||
}
|
||||
newApiErr = types.NewOpenAIError(errors.New(message), types.ErrorCodeBadResponseStatusCode, resp.StatusCode)
|
||||
if showBodyWhenFail {
|
||||
newApiErr.Err = buildErrWithBody(newApiErr.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user