Skip to content

Commit ea0f438

Browse files
authored
Do not suppress unsuccessful requests (#19)
1 parent 0924808 commit ea0f438

File tree

12 files changed

+87
-61
lines changed

12 files changed

+87
-61
lines changed

.github/workflows/build-and-publish.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
build-and-publish:
1212
name: Java Gradle
13-
uses: bakdata/ci-templates/.github/workflows/java-gradle-library.yaml@1.64.0
13+
uses: bakdata/ci-templates/.github/workflows/java-gradle-library.yaml@1.70.0
1414
with:
1515
java-version: 17
1616
secrets:

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
jobs:
1717
java-gradle-release:
1818
name: Java Gradle
19-
uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.64.0
19+
uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.70.0
2020
with:
2121
java-version: 17
2222
release-type: "${{ inputs.release-type }}"

build.gradle.kts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ description = "A Java client for KServe inference services."
22

33
plugins {
44
`java-library`
5-
id("com.bakdata.release") version "1.9.1"
6-
id("com.bakdata.sonar") version "1.9.1"
7-
id("com.bakdata.sonatype") version "1.9.1"
8-
id("io.freefair.lombok") version "8.12.2.1"
5+
id("com.bakdata.release") version "1.11.1"
6+
id("com.bakdata.sonar") version "1.11.1"
7+
id("com.bakdata.sonatype") version "1.11.1"
8+
id("io.freefair.lombok") version "8.14.2"
99
id("java-test-fixtures")
1010
}
1111

@@ -33,13 +33,12 @@ dependencies {
3333
implementation(group = "com.squareup.okhttp3", name = "okhttp", version = okHttpVersion)
3434
implementation(group = "org.json", name = "json", version = "20250107")
3535
implementation(group = "io.github.resilience4j", name = "resilience4j-retry", version = "1.7.1")
36-
implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.16")
36+
implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.17")
3737

3838
val junitVersion: String by project
39-
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-api", version = junitVersion)
40-
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-params", version = junitVersion)
41-
testRuntimeOnly(group = "org.junit.jupiter", name = "junit-jupiter-engine", version = junitVersion)
42-
testImplementation(group = "org.assertj", name = "assertj-core", version = "3.27.2")
39+
testRuntimeOnly(group = "org.junit.platform", name = "junit-platform-launcher")
40+
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter", version = junitVersion)
41+
testImplementation(group = "org.assertj", name = "assertj-core", version = "3.27.6")
4342
testImplementation(group = "com.squareup.okhttp3", name = "mockwebserver", version = okHttpVersion)
4443

4544
testFixturesImplementation(group = "com.squareup.okhttp3", name = "mockwebserver", version = okHttpVersion)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ version=2.1.2-SNAPSHOT
22
org.gradle.caching=true
33
org.gradle.parallel=true
44
okHttpVersion=4.12.0
5-
junitVersion=5.11.4
5+
junitVersion=5.13.4

gradle/wrapper/gradle-wrapper.jar

-19.7 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2025 bakdata
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.bakdata.kserve.client;
26+
27+
/**
28+
* Exception thrown when inference service request was unsuccessful.
29+
*/
30+
public final class InferenceRequestException extends IllegalArgumentException {
31+
32+
public InferenceRequestException(final String message) {
33+
super("Inference request failed: " + message);
34+
}
35+
}

src/main/java/com/bakdata/kserve/client/KServeClient.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ private static String getStringBody(final Response response) throws IOException
106106
}
107107
}
108108

109-
private static <T> Optional<T> processJsonResponse(final String stringBody, final Class<? extends T> responseType) {
109+
private static <T> T processJsonResponse(final String stringBody, final Class<? extends T> responseType) {
110110
try {
111-
return Optional.of(OBJECT_MAPPER.readValue(stringBody, responseType));
111+
return OBJECT_MAPPER.readValue(stringBody, responseType);
112112
} catch (final JsonProcessingException e) {
113113
throw new IllegalArgumentException("Could not process response json", e);
114114
}
@@ -139,7 +139,7 @@ private static Request getRequest(final String bodyString, final HttpUrl url) {
139139
* @throws IOException Thrown if the execution of the request fails or if the body of the response can not be
140140
* decoded to a string
141141
*/
142-
public <T> Optional<T> makeInferenceRequest(final I inputObject, final Class<? extends T> responseType,
142+
public <T> T makeInferenceRequest(final I inputObject, final Class<? extends T> responseType,
143143
final String modelNameSuffix)
144144
throws IOException {
145145
final Request httpRequest = getRequest(
@@ -168,19 +168,14 @@ private Response executeRequest(final Request httpRequest)
168168
.newCall(httpRequest).execute();
169169
}
170170

171-
private <T> Optional<T> processResponse(final Response response, final Class<? extends T> responseType)
171+
private <T> T processResponse(final Response response, final Class<? extends T> responseType)
172172
throws IOException {
173-
switch (response.code()) {
174-
case HttpURLConnection.HTTP_OK:
175-
return processJsonResponse(getStringBody(response), responseType);
176-
case HttpURLConnection.HTTP_NOT_FOUND:
177-
case HttpURLConnection.HTTP_BAD_REQUEST:
178-
final String errorMessage = this.extractErrorMessage(getStringBody(response));
179-
throw new InferenceRequestException(errorMessage);
180-
default:
181-
log.debug("Unknown response code: {}", response.code());
182-
return Optional.empty();
173+
final int responseCode = response.code();
174+
if (responseCode == HttpURLConnection.HTTP_OK) {
175+
return processJsonResponse(getStringBody(response), responseType);
183176
}
177+
final String errorMessage = this.extractErrorMessage(getStringBody(response));
178+
throw new InferenceRequestException(String.format("%d: %s", responseCode, errorMessage));
184179
}
185180

186181
@Slf4j
@@ -217,9 +212,4 @@ public Response intercept(final Chain chain) throws IOException {
217212
}
218213
}
219214

220-
protected static final class InferenceRequestException extends IllegalArgumentException {
221-
InferenceRequestException(final String message) {
222-
super("Inference request failed: " + message);
223-
}
224-
}
225215
}

0 commit comments

Comments
 (0)