Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/com/bakdata/kserve/client/KServeClientV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ protected String extractErrorMessage(final String stringBody) {
.or(() -> Optional.ofNullable(inferenceError.getDetail()))
.orElseThrow(() -> new InferenceRequestException("Could not extract error message."));
} catch (final JsonProcessingException e) {
throw new IllegalArgumentException("Could not process JSON error object", e);
log.warn("Could not parse error body as JSON: {}, {}", stringBody, e.getMessage());
return stringBody;
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/test/java/com/bakdata/kserve/client/KServeClientV2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ public MockResponse dispatch(@NotNull final RecordedRequest recordedRequest) {
.hasMessage("Inference request failed: 400: Not Found");
}

@Test
void testFallbackNonJsonBody() {
final Dispatcher dispatcher = new Dispatcher() {
@NotNull
@Override
public MockResponse dispatch(@NotNull final RecordedRequest recordedRequest) {
return new MockResponse.Builder()
.code(404)
.body("Not found")
.build();
}
};
this.mockServer.getMockWebServer().setDispatcher(dispatcher);

final KServeClientV2<String> client = KServeClientV2.<String>builder()
.serviceBaseUrl(this.mockServer.getServiceBaseUrl())
.modelName("test-model")
.httpClient(KServeClient.getHttpClient(Duration.ofMillis(10000)))
.build();

final InferenceRequest<String> fakeInferenceRequest = getFakeInferenceRequest("data");

this.softly.assertThatThrownBy(
() -> client.makeInferenceRequest(fakeInferenceRequest, FakePrediction.class, ""))
.isInstanceOf(InferenceRequestException.class)
.hasMessageContaining("Not found");
}

@Test
void testRetry() throws IOException {
this.mockServer.setUpForRetryTest();
Expand Down
Loading