Skip to content

Commit

Permalink
Handle issues while parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Feb 8, 2024
1 parent 1db2190 commit de5c957
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ private Optional<OpenAIException.Error> getErrorFromHttpResponse(HttpResponse<?>
} else {
return Optional.empty();
}
JsonNode errorNode = objectMapper.readTree(body).get("error");
if (errorNode == null) {
try {
JsonNode errorNode = objectMapper.readTree(body).get("error");
if (errorNode == null) {
return Optional.empty();
}
return Optional.of(objectMapper.treeToValue(errorNode, OpenAIException.Error.class));
} catch (JsonProcessingException ex) {
return Optional.empty();
}
return Optional.of(objectMapper.treeToValue(errorNode, OpenAIException.Error.class));
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
Expand Down

0 comments on commit de5c957

Please sign in to comment.