-
Notifications
You must be signed in to change notification settings - Fork 71
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
Respect the ScmComunicationException on token validation step #715
Changes from 1 commit
46114a4
520e887
6f1997f
1b4b316
deda774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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/ | ||
|
@@ -15,6 +15,7 @@ | |
import static java.net.HttpURLConnection.HTTP_NOT_FOUND; | ||
import static java.net.HttpURLConnection.HTTP_NO_CONTENT; | ||
import static java.net.HttpURLConnection.HTTP_OK; | ||
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; | ||
import static java.time.Duration.ofSeconds; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
@@ -37,6 +38,7 @@ | |
import org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException; | ||
import org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException; | ||
import org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException; | ||
import org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException; | ||
import org.eclipse.che.commons.lang.Pair; | ||
import org.eclipse.che.commons.lang.concurrent.LoggingUncaughtExceptionHandler; | ||
import org.slf4j.Logger; | ||
|
@@ -100,7 +102,8 @@ public BitbucketApiClient() { | |
* @throws ScmBadRequestException | ||
*/ | ||
public BitbucketUser getUser(String authenticationToken) | ||
throws ScmItemNotFoundException, ScmCommunicationException, ScmBadRequestException { | ||
throws ScmItemNotFoundException, ScmCommunicationException, ScmBadRequestException, | ||
ScmUnauthorizedException { | ||
final URI uri = apiServerUrl.resolve("user"); | ||
HttpRequest request = buildBitbucketApiRequest(uri, authenticationToken); | ||
LOG.trace("executeRequest={}", request); | ||
|
@@ -120,7 +123,8 @@ public BitbucketUser getUser(String authenticationToken) | |
|
||
public String getFileContent( | ||
String workspace, String repository, String source, String path, String authenticationToken) | ||
throws ScmItemNotFoundException, ScmCommunicationException, ScmBadRequestException { | ||
throws ScmItemNotFoundException, ScmCommunicationException, ScmBadRequestException, | ||
ScmUnauthorizedException { | ||
final URI uri = | ||
apiServerUrl.resolve( | ||
String.format("repositories/%s/%s/src/%s/%s", workspace, repository, source, path)); | ||
|
@@ -148,7 +152,8 @@ public String getFileContent( | |
* @throws ScmBadRequestException | ||
*/ | ||
public BitbucketUserEmail getEmail(String authenticationToken) | ||
throws ScmItemNotFoundException, ScmCommunicationException, ScmBadRequestException { | ||
throws ScmItemNotFoundException, ScmCommunicationException, ScmBadRequestException, | ||
ScmUnauthorizedException { | ||
final URI uri = apiServerUrl.resolve("user/emails"); | ||
HttpRequest request = buildBitbucketApiRequest(uri, authenticationToken); | ||
LOG.trace("executeRequest={}", request); | ||
|
@@ -174,7 +179,8 @@ public BitbucketUserEmail getEmail(String authenticationToken) | |
* scopes. | ||
*/ | ||
public Pair<String, String[]> getTokenScopes(String authenticationToken) | ||
throws ScmItemNotFoundException, ScmCommunicationException, ScmBadRequestException { | ||
throws ScmItemNotFoundException, ScmCommunicationException, ScmBadRequestException, | ||
ScmUnauthorizedException { | ||
final URI uri = apiServerUrl.resolve("user"); | ||
HttpRequest request = buildBitbucketApiRequest(uri, authenticationToken); | ||
LOG.trace("executeRequest={}", request); | ||
|
@@ -212,7 +218,8 @@ private <T> T executeRequest( | |
HttpClient httpClient, | ||
HttpRequest request, | ||
Function<HttpResponse<InputStream>, T> responseConverter) | ||
throws ScmBadRequestException, ScmItemNotFoundException, ScmCommunicationException { | ||
throws ScmBadRequestException, ScmItemNotFoundException, ScmCommunicationException, | ||
ScmUnauthorizedException { | ||
try { | ||
HttpResponse<InputStream> response = | ||
httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream()); | ||
|
@@ -228,6 +235,8 @@ private <T> T executeRequest( | |
throw new ScmBadRequestException(body); | ||
case HTTP_NOT_FOUND: | ||
throw new ScmItemNotFoundException(body); | ||
case HTTP_UNAUTHORIZED: | ||
throw new ScmUnauthorizedException(body, "github", "v1", ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move constant somewhere else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
right, fixed
Could you please elaborate on this? |
||
default: | ||
throw new ScmCommunicationException( | ||
"Unexpected status code " + response.statusCode() + " " + response.toString()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the benefits of logging error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not interrupt the workspace start in this case.