Improved fetch link error messages

This commit is contained in:
M66B 2022-05-31 19:48:50 +02:00
parent 19b968ba6f
commit 951bc37521
1 changed files with 10 additions and 2 deletions

View File

@ -47,6 +47,7 @@ import org.jsoup.nodes.Element;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
@ -138,8 +139,15 @@ public class FragmentDialogInsertLink extends FragmentDialogBase {
try {
int status = connection.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) {
String responseText = Helper.readStream(connection.getInputStream());
throw new IOException("HTTP " + status + ": " + responseText);
String error = "Error " + status + ": " + connection.getResponseMessage();
try {
InputStream is = connection.getErrorStream();
if (is != null)
error += "\n" + Helper.readStream(is);
} catch (Throwable ex) {
Log.w(ex);
}
throw new IOException(error);
}
// <title>...