Skip to content

Commit f614b5f

Browse files
authored
Merge pull request #37 from imsweb/update-okhttp
Update okhttp
2 parents 3b09b08 + e7d0b2e commit f614b5f

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ dependencies {
3939
api 'com.squareup.retrofit2:retrofit:2.9.0'
4040
api 'com.squareup.retrofit2:converter-jackson:2.9.0'
4141

42+
// retrofit will not update these dependencies to fix vulnerabilities
43+
api 'com.squareup.okhttp3:okhttp:4.9.3'
44+
4245
// newer version of dependency to fix vulnerability until converter-jackson is updated
4346
api 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
4447

src/main/java/com/imsweb/seerapi/client/ErrorInterceptor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@
55

66
import java.io.IOException;
77

8+
import org.jetbrains.annotations.NotNull;
9+
810
import com.fasterxml.jackson.databind.ObjectMapper;
911

1012
import okhttp3.Interceptor;
1113
import okhttp3.Response;
14+
import okhttp3.ResponseBody;
1215

1316
/**
1417
* Interceptor to catch all non-200 responses and convert them to exceptions.
1518
*/
1619
public class ErrorInterceptor implements Interceptor {
1720

21+
@NotNull
1822
@Override
1923
public Response intercept(Chain chain) throws IOException {
2024
Response response = chain.proceed(chain.request());
2125

2226
if (response.code() != 200) {
23-
// convert body to error response
2427
ErrorResponse error = null;
25-
if (response.body() != null) {
28+
29+
// convert body to error response
30+
ResponseBody body = response.body();
31+
if (body != null) {
2632
try {
27-
error = new ObjectMapper().readValue(response.body().byteStream(), ErrorResponse.class);
33+
error = new ObjectMapper().readValue(body.byteStream(), ErrorResponse.class);
2834
}
2935
catch (IOException e) {
3036
// sometimes the error message is not right format (like for 404 errors)

0 commit comments

Comments
 (0)