feat: add error logging for server responses in completion clients

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
extio-de
2026-05-08 19:38:48 +02:00
parent 7cc3374288
commit 210de3c62f
3 changed files with 14 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
package de.extio.lmlib.client.oai.completion;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.Duration;
@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatusCode;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestClientResponseException;
@@ -168,6 +171,15 @@ public abstract class AbstractCompletionClient implements Client, DisposableBean
return this.getModelNames(modelProfile, false).stream().findFirst().orElse("");
}
protected void logErrorResponse(final HttpStatusCode statusCode, final InputStream responseBody) {
try {
LOGGER.warn("Error response from server: {} {}", statusCode, new String(responseBody.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8));
}
catch (final IOException e) {
LOGGER.warn("Error response from server: {} <failed to read response body: {}>", statusCode, e.getMessage());
}
}
private List<String> loadModelNames(final ModelProfile modelProfile) {
try {
final var restClient = this.restClientBuilder.baseUrl(modelProfile.url()).build();

View File

@@ -74,6 +74,7 @@ public class ChatCompletionClient extends AbstractCompletionClient {
.body(requestBody)
.exchange((clientRequest, clientResponse) -> {
if (clientResponse.getStatusCode().isError()) {
this.logErrorResponse(clientResponse.getStatusCode(), clientResponse.getBody());
throw new IllegalStateException("Error response from server: " + clientResponse.getStatusCode());
}

View File

@@ -77,6 +77,7 @@ public class TextCompletionClient extends AbstractCompletionClient {
.body(requestBody)
.exchange((clientRequest, clientResponse) -> {
if (clientResponse.getStatusCode().isError()) {
this.logErrorResponse(clientResponse.getStatusCode(), clientResponse.getBody());
throw new IllegalStateException("Error response from server: " + clientResponse.getStatusCode());
}