Add human readable error messages

This commit is contained in:
stom79 2018-08-17 18:55:38 +02:00
parent ec863b071d
commit b7c667862a
2 changed files with 422 additions and 145 deletions

View File

@ -22,9 +22,12 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.*;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -131,8 +134,14 @@ public class API {
apiResponse.setInstance(instanceEntity);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return apiResponse;
}
@ -166,9 +175,12 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
setError(e.getStatusCode(), e);
}catch (Exception e) {
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
setDefaultError(e);
}
return apiResponse;
}
@ -185,8 +197,13 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return account;
@ -205,8 +222,14 @@ public class API {
account = parseAccountResponse(context, new JSONObject(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return account;
}
@ -230,8 +253,14 @@ public class API {
relationship = relationships.get(0);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return relationship;
}
@ -263,8 +292,14 @@ public class API {
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setRelationships(relationships);
return apiResponse;
@ -353,8 +388,13 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
@ -378,8 +418,14 @@ public class API {
statuses.add(status);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
return apiResponse;
@ -399,8 +445,14 @@ public class API {
statusContext = parseContext(new JSONObject(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return statusContext;
}
@ -452,8 +504,14 @@ public class API {
statuses = parseStatuses(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
return apiResponse;
@ -511,8 +569,14 @@ public class API {
statuses = parseStatuses(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
return apiResponse;
@ -560,8 +624,14 @@ public class API {
statuses = parseStatuses(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
return apiResponse;
@ -634,8 +704,14 @@ public class API {
accounts = parseAccountResponse(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
@ -677,8 +753,14 @@ public class API {
accounts = parseAccountResponse(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
@ -720,8 +802,14 @@ public class API {
statuses = parseStatuses(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
return apiResponse;
@ -755,8 +843,11 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return actionCode;
@ -884,8 +975,12 @@ public class API {
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
}else{
try {
@ -894,8 +989,12 @@ public class API {
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
}
return actionCode;
@ -945,8 +1044,13 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
@ -973,8 +1077,12 @@ public class API {
new HttpsConnection(context).post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return apiResponse;
}
@ -1066,8 +1174,14 @@ public class API {
notifications = parseNotificationResponse(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setNotifications(notifications);
return apiResponse;
@ -1096,8 +1210,14 @@ public class API {
attachment = parseAttachmentResponse(new JSONObject(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return attachment;
}
@ -1119,8 +1239,13 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return results;
@ -1166,8 +1291,13 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
@ -1192,8 +1322,14 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setEmojis(emojis);
return apiResponse;
@ -1213,8 +1349,14 @@ public class API {
lists = parseLists(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setLists(lists);
return apiResponse;
@ -1235,8 +1377,14 @@ public class API {
lists.add(list);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setLists(lists);
return apiResponse;
@ -1270,8 +1418,13 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setStatuses(statuses);
@ -1302,8 +1455,14 @@ public class API {
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;
@ -1327,8 +1486,14 @@ public class API {
lists.add(list);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setLists(lists);
return apiResponse;
@ -1357,8 +1522,12 @@ public class API {
new HttpsConnection(context).post(getAbsoluteUrl(String.format("/lists/%s/accounts", id)), 60, params, prefKeyOauthTokenT);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return apiResponse;
}
@ -1385,8 +1554,11 @@ public class API {
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
return actionCode;
@ -1409,8 +1581,14 @@ public class API {
lists.add(list);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setLists(lists);
return apiResponse;
@ -1450,8 +1628,14 @@ public class API {
lists.add(list);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
}catch (Exception e) {
setDefaultError(e);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
apiResponse.setLists(lists);
return apiResponse;
@ -2056,7 +2240,15 @@ public class API {
private void setError(int statusCode, Throwable error){
APIError = new Error();
APIError.setStatusCode(statusCode);
APIError.setError(statusCode + " - " + error.getMessage());
String message = statusCode + " - " + error.getMessage();
try {
JSONObject jsonObject = new JSONObject(error.getMessage());
String errorM = jsonObject.get("error").toString();
message = "Error " + statusCode + " : " + errorM;
} catch (JSONException e) {
e.printStackTrace();
}
APIError.setError(message);
apiResponse.setError(APIError);
}

View File

@ -45,6 +45,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
@ -145,12 +146,17 @@ public class HttpsConnection {
response = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
} else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpsURLConnection.getResponseCode();
httpsURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
@ -189,12 +195,17 @@ public class HttpsConnection {
response = new String(ByteStreams.toByteArray(httpURLConnection.getInputStream()));
}else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpURLConnection.getResponseCode();
httpURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
@ -223,12 +234,17 @@ public class HttpsConnection {
response = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
}else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpsURLConnection.getResponseCode();
httpsURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
@ -250,12 +266,17 @@ public class HttpsConnection {
response = new String(ByteStreams.toByteArray(httpURLConnection.getInputStream()));
}else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpURLConnection.getResponseCode();
httpURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
@ -308,12 +329,17 @@ public class HttpsConnection {
response = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
} else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpsURLConnection.getResponseCode();
httpsURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
@ -358,12 +384,17 @@ public class HttpsConnection {
response = new String(ByteStreams.toByteArray(httpURLConnection.getInputStream()));
} else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpURLConnection.getResponseCode();
httpURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
@ -727,10 +758,16 @@ public class HttpsConnection {
new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
} else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpsURLConnection.getResponseCode();
try {
httpsURLConnection.getInputStream().close();
@ -831,10 +868,16 @@ public class HttpsConnection {
new String(ByteStreams.toByteArray(httpURLConnection.getInputStream()));
} else {
String error = null;
if( httpURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpURLConnection.getErrorStream()));
else if( httpURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpURLConnection.getResponseCode();
try {
httpURLConnection.getInputStream().close();
@ -904,10 +947,16 @@ public class HttpsConnection {
new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
} else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpsURLConnection.getResponseCode();
try {
httpsURLConnection.getInputStream().close();
@ -965,10 +1014,16 @@ public class HttpsConnection {
new String(ByteStreams.toByteArray(httpURLConnection.getInputStream()));
} else {
String error = null;
if( httpURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpURLConnection.getErrorStream()));
else if( httpURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpURLConnection.getResponseCode();
try {
httpURLConnection.getInputStream().close();
@ -1088,12 +1143,17 @@ public class HttpsConnection {
if (200 != httpsURLConnection.getResponseCode()) {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpsURLConnection.getResponseCode();
httpsURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
@ -1239,12 +1299,17 @@ public class HttpsConnection {
if (200 != httpURLConnection.getResponseCode()) {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpURLConnection.getResponseCode();
httpURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
@ -1335,12 +1400,17 @@ public class HttpsConnection {
response = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
} else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpsURLConnection.getResponseCode();
httpsURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
@ -1387,12 +1457,17 @@ public class HttpsConnection {
response = new String(ByteStreams.toByteArray(httpURLConnection.getInputStream()));
} else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpURLConnection.getResponseCode();
httpURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
getSinceMaxId();
@ -1450,12 +1525,17 @@ public class HttpsConnection {
return httpsURLConnection.getResponseCode();
} else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpsURLConnection.getResponseCode();
httpsURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
}else {
@ -1499,12 +1579,17 @@ public class HttpsConnection {
return httpURLConnection.getResponseCode();
}else {
String error = null;
if( httpsURLConnection.getErrorStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getErrorStream()));
else if( httpsURLConnection.getInputStream() != null)
error = new String(ByteStreams.toByteArray(httpsURLConnection.getInputStream()));
if( httpsURLConnection.getErrorStream() != null) {
InputStream stream = httpsURLConnection.getErrorStream();
if (stream == null) {
stream = httpsURLConnection.getInputStream();
}
try (Scanner scanner = new Scanner(stream)) {
scanner.useDelimiter("\\Z");
error = scanner.next();
}
}
int responseCode = httpURLConnection.getResponseCode();
httpURLConnection.getInputStream().close();
throw new HttpsConnectionException(responseCode, error);
}
}