diff --git a/src/main/java/io/github/stefanbratanov/jvm/openai/OpenAIClient.java b/src/main/java/io/github/stefanbratanov/jvm/openai/OpenAIClient.java index 4848bb5..e583e86 100644 --- a/src/main/java/io/github/stefanbratanov/jvm/openai/OpenAIClient.java +++ b/src/main/java/io/github/stefanbratanov/jvm/openai/OpenAIClient.java @@ -145,11 +145,15 @@ private Optional 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); }