Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
catching the ProtocolException and rethrowing it as an IOException
Browse files Browse the repository at this point in the history
  • Loading branch information
zugaldia committed Nov 4, 2015
1 parent ddd60bf commit fb502ca
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public HTTPRequest createRequest(long nativePtr, String resourceUrl, String user
}

public class HTTPRequest implements Callback {
private final String LOG_TAG = HTTPRequest.class.getName();

private long mNativePtr = 0;

private Call mCall;
Expand Down Expand Up @@ -76,6 +78,8 @@ public void cancel() {

@Override
public void onFailure(Request request, IOException e) {
Log.d(LOG_TAG, "onFailure: " + e.getMessage());

int type = PERMANENT_ERROR;
if ((e instanceof UnknownHostException) || (e instanceof SocketException) || (e instanceof ProtocolException) || (e instanceof SSLException)) {
type = CONNECTION_ERROR;
Expand All @@ -93,10 +97,20 @@ public void onResponse(Response response) throws IOException {
byte[] body;
try {
body = response.body().bytes();
} catch (ProtocolException e) {
Log.d(LOG_TAG , "ProtocolException: " + e.getMessage());
throw new IOException("ProtocolException", e);
} finally {
response.body().close();
}

// if (body == null) {
// // Avoids JNI DETECTED ERROR IN APPLICATION: jarray was NULL in call to
// // GetByteArrayElements from nativeOnResponse()
// Log.d(LOG_TAG, "nativeOnResponse skipped due to empty body.");
// throw new IOException("nativeOnResponse skipped due to empty body.");
// }

nativeOnResponse(mNativePtr, response.code(), response.message(), response.header("ETag"), response.header("Last-Modified"), response.header("Cache-Control"), response.header("Expires"), body);
}
}
Expand Down

0 comments on commit fb502ca

Please sign in to comment.