Skip to content

Commit

Permalink
Add status code to process error response
Browse files Browse the repository at this point in the history
Signed-off-by: zane-neo <[email protected]>
  • Loading branch information
zane-neo committed Feb 29, 2024
1 parent fbbf172 commit a553af4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ public static ModelTensors processOutput(
return ModelTensors.builder().statusCode(RestStatus.OK.getStatus()).mlModelTensors(modelTensors).build();
}

public static ModelTensors processErrorResponse(String errorResponse) {
public static ModelTensors processErrorResponse(Integer statusCode,String errorResponse) {
return ModelTensors
.builder()
.statusCode(RestStatus.INTERNAL_SERVER_ERROR.getStatus())
.statusCode(statusCode)
.mlModelTensors(List.of(ModelTensor.builder().dataAsMap(Map.of("remote_response", errorResponse)).build()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ private void processResponse(
ModelTensors tensors;
if (Strings.isBlank(body)) {
log.error("Remote model response body is empty!");
tensors = processErrorResponse("null");
tensors = processErrorResponse(statusCode, "null");
} else {
if (statusCode < HttpStatus.SC_OK || statusCode > HttpStatus.SC_MULTIPLE_CHOICES) {
log.error("Remote server returned error code: {}", statusCode);
tensors = processErrorResponse(body);
tensors = processErrorResponse(statusCode, body);
} else {
try {
tensors = processOutput(body, connector, scriptService, parameters);
} catch (Exception e) {
log.error("Failed to process response body: {}", body, e);
tensors = processErrorResponse(body);
tensors = processErrorResponse(statusCode, body);
}
}
}
Expand Down

0 comments on commit a553af4

Please sign in to comment.