Check for null error streams

pull/203/head
M66B 4 years ago
parent ce3f3dd387
commit 60c9d33a65

@ -1218,11 +1218,13 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
InputStream inputStream = (status == HttpsURLConnection.HTTP_OK InputStream inputStream = (status == HttpsURLConnection.HTTP_OK
? urlConnection.getInputStream() : urlConnection.getErrorStream()); ? urlConnection.getInputStream() : urlConnection.getErrorStream());
if (inputStream != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line; String line;
while ((line = br.readLine()) != null) while ((line = br.readLine()) != null)
response.append(line); response.append(line);
}
if (status == HttpsURLConnection.HTTP_FORBIDDEN) { if (status == HttpsURLConnection.HTTP_FORBIDDEN) {
// {"message":"API rate limit exceeded for ...","documentation_url":"https://developer.github.com/v3/#rate-limiting"} // {"message":"API rate limit exceeded for ...","documentation_url":"https://developer.github.com/v3/#rate-limiting"}

@ -215,7 +215,9 @@ public class DeepL {
if (status != HttpsURLConnection.HTTP_OK) { if (status != HttpsURLConnection.HTTP_OK) {
String error = "Error " + status + ": " + connection.getResponseMessage(); String error = "Error " + status + ": " + connection.getResponseMessage();
try { try {
error += "\n" + Helper.readStream(connection.getErrorStream()); InputStream is = connection.getErrorStream();
if (is != null)
error += "\n" + Helper.readStream(is);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
} }
@ -257,7 +259,9 @@ public class DeepL {
if (status != HttpsURLConnection.HTTP_OK) { if (status != HttpsURLConnection.HTTP_OK) {
String error = "Error " + status + ": " + connection.getResponseMessage(); String error = "Error " + status + ": " + connection.getResponseMessage();
try { try {
error += "\n" + Helper.readStream(connection.getErrorStream()); InputStream is = connection.getErrorStream();
if (is != null)
error += "\n" + Helper.readStream(is);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
} }

Loading…
Cancel
Save