mirror of
https://github.com/google/nomulus
synced 2025-12-23 06:15:42 +00:00
UrlConnectionException loses error info (#2648)
It does not get the error message for 400+ status codes. It fails to get the status code if the response has neither data nor error.
This commit is contained in:
@@ -37,13 +37,14 @@ public class UrlConnectionException extends RuntimeException {
|
|||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
byte[] resultContent;
|
byte[] resultContent;
|
||||||
int responseCode;
|
int responseCode = 0;
|
||||||
try {
|
try {
|
||||||
resultContent = ByteStreams.toByteArray(connection.getInputStream());
|
|
||||||
responseCode = connection.getResponseCode();
|
responseCode = connection.getResponseCode();
|
||||||
} catch (IOException e) {
|
resultContent =
|
||||||
resultContent = new byte[] {};
|
ByteStreams.toByteArray(
|
||||||
responseCode = 0;
|
responseCode < 400 ? connection.getInputStream() : connection.getErrorStream());
|
||||||
|
} catch (IOException | NullPointerException e) {
|
||||||
|
resultContent = "-- Response is missing or has malformed content --".getBytes(UTF_8);
|
||||||
}
|
}
|
||||||
StringBuilder result =
|
StringBuilder result =
|
||||||
new StringBuilder(2048 + resultContent.length)
|
new StringBuilder(2048 + resultContent.length)
|
||||||
|
|||||||
Reference in New Issue
Block a user