mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[platform] fault-tolerant diagnostic composition for HttpRequests (IDEA-156936)
This commit is contained in:
@@ -64,6 +64,9 @@ public final class HttpRequests {
|
||||
|
||||
|
||||
public interface Request {
|
||||
@NotNull
|
||||
String getURL();
|
||||
|
||||
@NotNull
|
||||
URLConnection getConnection() throws IOException;
|
||||
|
||||
@@ -129,17 +132,23 @@ public final class HttpRequests {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String createErrorMessage(@NotNull IOException e, @NotNull Request request, boolean includeHeaders) throws IOException {
|
||||
URLConnection connection = request.getConnection();
|
||||
public static String createErrorMessage(@NotNull IOException e, @NotNull Request request, boolean includeHeaders) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Cannot download '").append(connection.getURL().toExternalForm()).append("': ").append(e.getMessage());
|
||||
if (includeHeaders) {
|
||||
builder.append("\n, headers: ").append(connection.getHeaderFields());
|
||||
}
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection)connection;
|
||||
builder.append("\n, response: ").append(httpConnection.getResponseCode()).append(' ').append(httpConnection.getResponseMessage());
|
||||
|
||||
builder.append("Cannot download '").append(request.getURL()).append("': ").append(e.getMessage());
|
||||
|
||||
try {
|
||||
URLConnection connection = request.getConnection();
|
||||
if (includeHeaders) {
|
||||
builder.append("\n, headers: ").append(connection.getHeaderFields());
|
||||
}
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection)connection;
|
||||
builder.append("\n, response: ").append(httpConnection.getResponseCode()).append(' ').append(httpConnection.getResponseMessage());
|
||||
}
|
||||
}
|
||||
catch (Throwable ignored) { }
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -249,6 +258,12 @@ public final class HttpRequests {
|
||||
myBuilder = builder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getURL() {
|
||||
return myBuilder.myUrl;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public URLConnection getConnection() throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user