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

View File

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