Skip to content

Commit 73de723

Browse files
committed
Initial
1 parent f530ddf commit 73de723

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

core/src/main/java/com/sap/ai/sdk/core/common/ClientResponseHandler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ private T parseResponse(@Nonnull final ClassicHttpResponse response) throws E {
7878
throw exceptionConstructor.apply("Response was empty.", null);
7979
}
8080
val content = getContent(responseEntity);
81-
log.debug("Parsing response from JSON response: {}", content);
81+
log.debug("Deserializing JSON response to type {}: {}", responseType.getSimpleName(), content);
8282
try {
8383
return objectMapper.readValue(content, responseType);
8484
} catch (final JsonProcessingException e) {
85-
log.error("Failed to parse the following response: {}", content);
85+
log.error("Failed to deserialize the response to type: {}", responseType.getSimpleName(), e);
8686
throw exceptionConstructor.apply("Failed to parse response", e);
8787
}
8888
}
@@ -103,10 +103,11 @@ private String getContent(@Nonnull final HttpEntity entity) {
103103
*/
104104
@SuppressWarnings("PMD.CloseResource")
105105
public void buildExceptionAndThrow(@Nonnull final ClassicHttpResponse response) throws E {
106+
val errorCode = response.getCode();
106107
val exception =
107108
exceptionConstructor.apply(
108109
"Request failed with status %s %s"
109-
.formatted(response.getCode(), response.getReasonPhrase()),
110+
.formatted(errorCode, response.getReasonPhrase()),
110111
null);
111112
val entity = response.getEntity();
112113
if (entity == null) {
@@ -122,7 +123,8 @@ public void buildExceptionAndThrow(@Nonnull final ClassicHttpResponse response)
122123
throw exception;
123124
}
124125

125-
log.error("The service responded with an HTTP error and the following content: {}", content);
126+
log.error("The service responded with HTTP error code {}", errorCode);
127+
log.debug("The service responded with HTTP error code {} and content: {}", errorCode, content);
126128
val contentType = ContentType.parse(entity.getContentType());
127129
if (!ContentType.APPLICATION_JSON.isSameMimeType(contentType)) {
128130
throw exception;

core/src/main/java/com/sap/ai/sdk/core/common/ClientStreamingHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public Stream<D> handleStreamingResponse(@Nonnull final ClassicHttpResponse resp
7777
try {
7878
return objectMapper.readValue(data, responseType);
7979
} catch (final IOException e) { // exception message e gets lost
80-
log.error("Failed to parse the following response: {}", line);
80+
log.error("Failed to parse thr streamed response.");
81+
log.debug("Failed to parse the following response: {}", line, e);
8182
throw exceptionConstructor.apply("Failed to parse delta message: " + line, e);
8283
}
8384
});

0 commit comments

Comments
 (0)