Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extend message on http sender response #4355

Closed
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -884,12 +884,19 @@ private MavenRepository applyMirrors(MavenRepository repository) {

@Getter
public static class HttpSenderResponseException extends Exception {
@Nullable
private final Integer responseCode;

private final int responseCode;

private final String body;

public HttpSenderResponseException(@Nullable Throwable cause, @Nullable Integer responseCode,
public HttpSenderResponseException(@Nullable Throwable cause,
@Nullable Integer responseCode,
String body) {
this(cause, responseCode == null ? 0 : responseCode, body);
}

public HttpSenderResponseException(@Nullable Throwable cause,
int responseCode,
String body) {
super(cause);
this.responseCode = responseCode;
@@ -903,26 +910,35 @@ public HttpSenderResponseException(@Nullable Throwable cause, @Nullable Integer
* For 408 TIMEOUT, 425 TOO_EARLY, and 429 TOO_MANY_REQUESTS, these are likely to change if not cached.
*/
public boolean isClientSideException() {
if (responseCode == null || responseCode < 400 || responseCode > 499) {
if (responseCode < 400 || responseCode > 499) {
return false;
}
return responseCode != 408 && responseCode != 425 && responseCode != 429;
}

@Override
public String getMessage() {
return responseCode == null ?
requireNonNull(getCause()).getMessage() :
"HTTP " + responseCode;
String message = "HTTP " + responseCode;
if (responseCode < 0) {
message += " - Connection failed";
} else if (responseCode > 399) {
message += "\n" + body;
}

Throwable cause = getCause();
if (cause != null && cause.getMessage() != null) {
message += "\nCaused by: " + cause.getMessage();
}
return message;
}

public boolean isAccessDenied() {
return responseCode != null && 400 < responseCode && responseCode <= 403;
return 400 < responseCode && responseCode <= 403;
}

// Any response code below 100 implies that no connection was made. Sometimes 0 or -1 is used for connection failures.
public boolean isServerReached() {
return responseCode != null && responseCode >= 100;
return responseCode >= 100;
}
}