Skip to content

Commit 3767017

Browse files
committed
fix: ErrorInterceptor empty body check for okhttp 5
1 parent c86f235 commit 3767017

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

modules/common/src/main/java/com/ibm/cloud/cloudant/internal/ErrorTransformInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Response intercept(Chain chain) throws IOException {
3232
// Don't modify the request, but get the response
3333
Response response = chain.proceed(chain.request());
3434
if (!response.isSuccessful() // skip successful responses
35-
&& response.body() != null // skip cases with no body
35+
&& response.body() != null && !ResponseBody.EMPTY.equals(response.body()) // skip cases with no body
3636
&& response.body().contentType() != null // skip cases with no content type
3737
&& "application".equals(response.body().contentType().type())
3838
&& "json".equals(response.body().contentType().subtype()) // we only want to work with application/json

modules/common/src/test/java/com/ibm/cloud/cloudant/internal/ErrorTransformInterceptorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.google.gson.JsonObject;
3838
import com.ibm.cloud.sdk.core.security.NoAuthAuthenticator;
3939
import com.ibm.cloud.sdk.core.util.GsonSingleton;
40-
import static org.junit.Assert.assertNull;
4140
import static org.testng.Assert.assertEquals;
4241
import static org.testng.Assert.assertFalse;
4342
import static org.testng.Assert.assertTrue;
@@ -340,7 +339,7 @@ void runTest(Interceptor interceptor) throws IOException {
340339
} else {
341340
// If we aren't asserting a specific part of augment check the body is unchanged
342341
if ("HEAD" == r.request().method()) {
343-
assertNull(r.body());
342+
assertEquals(r.body(), ResponseBody.EMPTY);
344343
} else {
345344
assertEquals(r.body().string(), responseBody);
346345
}

0 commit comments

Comments
 (0)