Fix the crash from okhttp interceptor (#168)
Summary: Add a null check before creating a new response Fixes #166 Pull Request resolved: https://github.com/facebook/Sonar/pull/168 Reviewed By: jknoxville Differential Revision: D8915871 Pulled By: passy fbshipit-source-id: aa93273f6fe90a8160133331e0844f67ff7e620a
This commit is contained in:
committed by
Facebook Github Bot
parent
02cd3ba560
commit
65239838f2
@@ -1,4 +1,10 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
/*
|
||||
* Copyright (c) 2004-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
package com.facebook.sonar.plugins.network;
|
||||
|
||||
import android.util.Log;
|
||||
@@ -39,10 +45,14 @@ public class SonarOkhttpInterceptor implements Interceptor {
|
||||
ResponseInfo responseInfo = convertResponse(response, body, randInt);
|
||||
plugin.reportResponse(responseInfo);
|
||||
// Creating new response as can't used response.body() more than once
|
||||
if (responseInfo.body != null) {
|
||||
return response
|
||||
.newBuilder()
|
||||
.body(ResponseBody.create(body.contentType(), responseInfo.body))
|
||||
.build();
|
||||
} else {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] bodyToByteArray(final Request request) {
|
||||
|
||||
Reference in New Issue
Block a user