Skip to content

Commit 3f34ecf

Browse files
fix valid response check
1 parent f159a96 commit 3f34ecf

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/main/java/com/mindee/http/MindeeApiCommon.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ protected String getUserAgent() {
3434
}
3535

3636
/**
37-
* Checks if the status code is in the 2xx range.
37+
* Checks if the status code is out of the 2xx-3xx range.
3838
* @param statusCode the status code to check.
3939
* @return {@code true} if the status code is in the 2xx range, false otherwise.
4040
*/
41-
protected boolean is2xxStatusCode(int statusCode) {
42-
return statusCode >= 200 && statusCode <= 299;
41+
protected boolean isInvalidStatusCode(int statusCode) {
42+
return statusCode < 200 || statusCode > 399;
4343
}
4444

4545
protected String readRawResponse(HttpEntity responseEntity) throws IOException {

src/main/java/com/mindee/http/MindeeHttpApi.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> documentQueueGet(
172172
get, response -> {
173173
HttpEntity responseEntity = response.getEntity();
174174
int statusCode = response.getCode();
175-
if (!is2xxStatusCode(statusCode)) {
175+
if (isInvalidStatusCode(statusCode)) {
176176
throw getHttpError(parametricType, response);
177177
}
178178
String rawResponse = readRawResponse(responseEntity);
@@ -222,7 +222,7 @@ public <DocT extends Inference> PredictResponse<DocT> predictPost(
222222
post, response -> {
223223
HttpEntity responseEntity = response.getEntity();
224224
int statusCode = response.getCode();
225-
if (!is2xxStatusCode(statusCode)) {
225+
if (isInvalidStatusCode(statusCode)) {
226226
throw getHttpError(parametricType, response);
227227
}
228228
if (responseEntity.getContentLength() == 0) {
@@ -267,7 +267,7 @@ public <DocT extends Inference> AsyncPredictResponse<DocT> predictAsyncPost(
267267
post, response -> {
268268
HttpEntity responseEntity = response.getEntity();
269269
int statusCode = response.getCode();
270-
if (!is2xxStatusCode(statusCode)) {
270+
if (isInvalidStatusCode(statusCode)) {
271271
throw getHttpError(parametricType, response);
272272
}
273273
if (responseEntity.getContentLength() == 0) {
@@ -308,7 +308,7 @@ public <DocT extends Inference> WorkflowResponse<DocT> executeWorkflowPost(
308308
return httpClient.execute(post, response -> {
309309
HttpEntity responseEntity = response.getEntity();
310310
int statusCode = response.getCode();
311-
if (!is2xxStatusCode(statusCode)) {
311+
if (isInvalidStatusCode(statusCode)) {
312312
throw getHttpError(parametricType, response);
313313
}
314314
if (responseEntity.getContentLength() == 0) {

src/main/java/com/mindee/http/MindeeHttpApiV2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public JobResponse getJobResponse(
117117
get, response -> {
118118
HttpEntity responseEntity = response.getEntity();
119119
int statusCode = response.getCode();
120-
if (!is2xxStatusCode(statusCode)) {
120+
if (isInvalidStatusCode(statusCode)) {
121121
throw getHttpError(response);
122122
}
123123
try {
@@ -156,7 +156,7 @@ public InferenceResponse getInferenceFromQueue(String jobId) {
156156
HttpEntity entity = response.getEntity();
157157
int status = response.getCode();
158158
try {
159-
if (!is2xxStatusCode(status)) {
159+
if (isInvalidStatusCode(status)) {
160160
throw getHttpError(response);
161161
}
162162
String raw = EntityUtils.toString(entity, StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)