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 76f172d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class GithubApiClient {
/** GitHub endpoint URL. */
public static final String GITHUB_SAAS_ENDPOINT = "https://github.com";

public static final String GITHUB_SAAS_ENDPOINT_API = "https://api.github.com";
public static final String GITHUB_SAAS_ENDPOINT_API = "https://api.githubb.com";

public static final String GITHUB_SAAS_ENDPOINT_RAW = "https://raw.githubusercontent.com";

Expand Down 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 76f172d

Please sign in to comment.