mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract createErrorMessage (IDEA-CR-1104)
This commit is contained in:
@@ -17,7 +17,6 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@@ -164,7 +163,7 @@ public class DownloadUtil {
|
||||
}
|
||||
|
||||
private static void download(@Nullable final ProgressIndicator progress,
|
||||
@NotNull final String location,
|
||||
@NotNull String location,
|
||||
@NotNull final OutputStream output) throws IOException {
|
||||
final String originalText = progress != null ? progress.getText() : null;
|
||||
substituteContentLength(progress, originalText, -1);
|
||||
@@ -184,18 +183,14 @@ public class DownloadUtil {
|
||||
NetUtils.copyStreamContent(progress, request.getInputStream(), output, contentLength);
|
||||
}
|
||||
catch (IOException e) {
|
||||
HttpURLConnection connection = (HttpURLConnection)request.getConnection();
|
||||
throw new IOException("Cannot download '" + location +
|
||||
", headers: " + connection.getHeaderFields() +
|
||||
"', response code: " + connection.getResponseCode() +
|
||||
", response message: " + connection.getResponseMessage(), e);
|
||||
throw new IOException(HttpRequests.createErrorMessage(e, request), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IOException("Cannot download '" + location, e);
|
||||
throw new IOException("Cannot download " + location, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,17 @@ public abstract class HttpRequests {
|
||||
protected HttpRequests() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String createErrorMessage(@NotNull IOException e, @NotNull Request request) throws IOException {
|
||||
URLConnection connection = request.getConnection();
|
||||
String errorMessage = "Cannot download '" + connection.getURL().toExternalForm() + "': " + e.getMessage() + "\n, headers: " + connection.getHeaderFields();
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection)connection;
|
||||
errorMessage += "\n, response: " + httpConnection.getResponseCode() + ' ' + httpConnection.getResponseMessage();
|
||||
}
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public abstract static class RequestBuilder {
|
||||
private final String myUrl;
|
||||
private int myConnectTimeout = HttpConfigurable.CONNECTION_TIMEOUT;
|
||||
@@ -269,14 +280,7 @@ public abstract class HttpRequests {
|
||||
deleteFile = false;
|
||||
}
|
||||
catch (IOException e) {
|
||||
URLConnection connection = getConnection();
|
||||
String errorMessage = "Cannot download '" + builder.myUrl + ", headers: " + connection.getHeaderFields();
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection)connection;
|
||||
errorMessage += "', response code: " + httpConnection.getResponseCode()
|
||||
+ ", response message: " + httpConnection.getResponseMessage();
|
||||
}
|
||||
throw new IOException(errorMessage, e);
|
||||
throw new IOException(createErrorMessage(e, this), e);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user