Check for null error streams

This commit is contained in:
M66B 2021-08-14 09:23:01 +02:00
parent ce3f3dd387
commit 60c9d33a65
2 changed files with 12 additions and 6 deletions

View File

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

View File

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