# reading http reponse (code and body) on server failures while executing HTTP requests

This commit is contained in:
Lukas Niemeier committed 2013-05-04 12:02:51 +08:00
1 parent ff65435b9e
commit caf8ea0a2c
2 files changed
+11 -4

No files matched your search

@@ -1,5 +1,6 @@
package com.sap.sailing.racecommittee.app.data.http;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
@@ -45,10 +46,16 @@ public abstract class HttpRequest {
connection.setConnectTimeout(5000);
connection.setReadTimeout(15000);
InputStream stream = execute(connection);
ExLog.i(TAG, String.format("HTTP request executed. Validating response..."));
InputStream stream = null;
try {
stream = execute(connection);
} catch (FileNotFoundException fnfe) {
throw new FileNotFoundException(String.format("%s\nHTTP response code: %d.\nHTTP response body: %s.",
fnfe.getMessage(), connection.getResponseCode(), connection.getResponseMessage()));
}
validateHttpResponse(connection);
ExLog.i(TAG, String.format("HTTP request executed."));
return stream;
}
@@ -52,7 +52,7 @@ public class EventSenderTask extends AsyncTask<Intent, Void, Pair<Intent, Intege
}
ExLog.i(TAG, "Post successful for the following event: " + serializedEvent);
} catch (Exception e) {
ExLog.e(TAG, String.format("Post not successful, exception occured: ", e.toString()));
ExLog.e(TAG, String.format("Post not successful, exception occured: %s", e.toString()));
return Pair.create(intent, -1);
}
return Pair.create(intent, 0);