From e14013a96ced3fbc4baa4561bd614be155ac2b85 Mon Sep 17 00:00:00 2001 From: Stephen Hynes Date: Mon, 5 Sep 2016 14:42:45 +0100 Subject: [PATCH] handle response failures --- .../main/java/com/logentries/net/LogentriesClient.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/logentries/net/LogentriesClient.java b/lib/src/main/java/com/logentries/net/LogentriesClient.java index bc33ec9..797b8e0 100644 --- a/lib/src/main/java/com/logentries/net/LogentriesClient.java +++ b/lib/src/main/java/com/logentries/net/LogentriesClient.java @@ -1,6 +1,7 @@ package com.logentries.net; import org.apache.http.client.HttpClient; +import org.apache.http.client.HttpResponseException; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; @@ -13,6 +14,8 @@ import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; +import android.util.Log; + public class LogentriesClient { // Logentries server endpoints for logs data. private static final String LE_TOKEN_API = "data.logentries.com"; // For token-based stream input @@ -148,7 +151,12 @@ public void write(String data) throws IOException { } else { // HTTP input mode. postRequest.setEntity(new StringEntity(data, "UTF8")); - httpClient.execute(postRequest); + try { + httpClient.execute(postRequest); + } catch (HttpResponseException ex) { + Log.e("LogentriesAndroidLogger", "Received status code:" + ex.getStatusCode()); + Log.e("LogentriesAndroidLogger", "Error message:" + ex.getMessage()); + } } }