Skip to content

Commit

Permalink
refactor: modifying log levels and adding more logs to display error …
Browse files Browse the repository at this point in the history
…details (#3337) (#3359)

Signed-off-by: Pavan Yekbote <[email protected]>
(cherry picked from commit 441af6e)

Co-authored-by: Pavan Yekbote <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and pyek-bot authored Jan 9, 2025
1 parent 0b5fe2a commit 1e63f15
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void onHeaders(SdkHttpResponse response) {
log.debug("received response headers: " + sdkResponse.headers());
this.statusCode = sdkResponse.statusCode();
if (statusCode < HttpStatus.SC_OK || statusCode > HttpStatus.SC_MULTIPLE_CHOICES) {
log.error("Received error from remote service with status code {}, response headers: {}", statusCode, sdkResponse.headers());
handleThrottlingInHeader(sdkResponse);
// add more handling here for other exceptions in headers
}
Expand All @@ -101,7 +102,7 @@ public void onStream(Publisher<ByteBuffer> stream) {

@Override
public void onError(Throwable error) {
log.error(error.getMessage(), error);
log.error("Received error from remote service: {}", error.getMessage(), error);
RestStatus status = (statusCode == null) ? RestStatus.INTERNAL_SERVER_ERROR : RestStatus.fromCode(statusCode);
String errorMessage = "Error communicating with remote model: " + error.getMessage();
actionListener.onFailure(new OpenSearchStatusException(errorMessage, status));
Expand Down Expand Up @@ -173,6 +174,7 @@ private void response() {
String body = responseBody.toString();

if (exceptionHolder.get() != null) {
log.error("Remote server returned exception with status code: {} and body: {}", statusCode, body);
actionListener.onFailure(exceptionHolder.get());
return;
}
Expand All @@ -184,7 +186,7 @@ private void response() {
}

if (statusCode < HttpStatus.SC_OK || statusCode > HttpStatus.SC_MULTIPLE_CHOICES) {
log.error("Remote server returned error code: {}", statusCode);
log.error("Remote service returned error code: {} with body: {}", statusCode, body);
actionListener.onFailure(new OpenSearchStatusException(REMOTE_SERVICE_ERROR + body, RestStatus.fromCode(statusCode)));
return;
}
Expand Down

0 comments on commit 1e63f15

Please sign in to comment.