Skip to content

Commit

Permalink
fixup! Intercept ScmComunicationException on workspace start
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Sep 11, 2024
1 parent 1b4b316 commit deda774
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2023 Red Hat, Inc.
* Copyright (c) 2012-2024 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ private <T> T executeRequest(
Function<HttpResponse<InputStream>, T> responseConverter)
throws ScmBadRequestException, ScmItemNotFoundException, ScmCommunicationException,
ScmUnauthorizedException {
String provider = GITHUB_SAAS_ENDPOINT.equals(getServerUrl()) ? "github" : "github-server";
try {
HttpResponse<InputStream> response =
httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
Expand All @@ -300,11 +301,11 @@ private <T> T executeRequest(
throw new ScmUnauthorizedException(body, "github", "v2", "");
default:
throw new ScmCommunicationException(
"Unexpected status code " + statusCode + " " + body, statusCode, "github");
"Unexpected status code " + statusCode + " " + body, statusCode, provider);
}
}
} catch (IOException | InterruptedException | UncheckedIOException e) {
throw new ScmCommunicationException(e.getMessage(), e, "github");
throw new ScmCommunicationException(e.getMessage(), e, provider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private <T> T executeRequest(
HttpClient httpClient, HttpRequest request, Function<InputStream, T> bodyConverter)
throws ScmBadRequestException, ScmItemNotFoundException, ScmCommunicationException,
ScmUnauthorizedException {
String provider = "http://gitlab.com".equals(serverUrl.toString()) ? "gitlab" : "gitlab-server";
try {
HttpResponse<InputStream> response =
httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
Expand All @@ -169,11 +170,11 @@ private <T> T executeRequest(
throw new ScmCommunicationException(
"Unexpected status code " + response.statusCode() + " " + response,
response.statusCode(),
"gitlab");
provider);
}
}
} catch (IOException | InterruptedException | UncheckedIOException e) {
throw new ScmCommunicationException(e.getMessage(), e, "gitlab");
throw new ScmCommunicationException(e.getMessage(), e, provider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public ScmCommunicationException(String message, int statusCode, String provider
this.provider = provider;
}

public ScmCommunicationException(String message, int statusCode) {
super(message);
this.statusCode = statusCode;
}

public ScmCommunicationException(String message, Throwable cause) {
super(message, cause);
}
Expand Down

0 comments on commit deda774

Please sign in to comment.