From 1b4b3163383533cbef8b1328fa659b34b2a5b868 Mon Sep 17 00:00:00 2001 From: ivinokur Date: Wed, 11 Sep 2024 13:56:38 +0300 Subject: [PATCH] fixup! Intercept ScmComunicationException on workspace start --- .../azure/devops/AzureDevOpsApiClient.java | 4 +++- .../HttpBitbucketServerApiClient.java | 4 +++- .../server/bitbucket/BitbucketApiClient.java | 6 ++++-- .../server/github/GithubApiClient.java | 4 ++-- .../server/gitlab/GitlabApiClient.java | 5 +++-- .../factory/server/ApiExceptionMapper.java | 6 +++++- .../exception/ScmCommunicationException.java | 19 +++++++++++++++++-- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsApiClient.java b/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsApiClient.java index a18ae884d21..dae10eb58d2 100644 --- a/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsApiClient.java +++ b/wsmaster/che-core-api-factory-azure-devops/src/main/java/org/eclipse/che/api/factory/server/azure/devops/AzureDevOpsApiClient.java @@ -147,7 +147,9 @@ private T executeRequest( throw new ScmItemNotFoundException(body); default: throw new ScmCommunicationException( - "Unexpected status code " + response.statusCode() + " " + response.toString()); + "Unexpected status code " + response.statusCode() + " " + response, + response.statusCode(), + "azure-devops"); } } } catch (IOException | InterruptedException | UncheckedIOException e) { diff --git a/wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/HttpBitbucketServerApiClient.java b/wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/HttpBitbucketServerApiClient.java index a92c2b8b614..6cf5383c715 100644 --- a/wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/HttpBitbucketServerApiClient.java +++ b/wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/HttpBitbucketServerApiClient.java @@ -411,7 +411,9 @@ private T executeRequest( throw new ScmItemNotFoundException(body); default: throw new ScmCommunicationException( - "Unexpected status code " + response.statusCode() + " " + response.toString()); + "Unexpected status code " + response.statusCode() + " " + response, + response.statusCode(), + "bitbucket"); } } } catch (IOException | InterruptedException | UncheckedIOException e) { diff --git a/wsmaster/che-core-api-factory-bitbucket/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketApiClient.java b/wsmaster/che-core-api-factory-bitbucket/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketApiClient.java index 764884f19fe..6f0ef8a23f3 100644 --- a/wsmaster/che-core-api-factory-bitbucket/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketApiClient.java +++ b/wsmaster/che-core-api-factory-bitbucket/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketApiClient.java @@ -239,11 +239,13 @@ private T executeRequest( throw new ScmUnauthorizedException(body, "bitbucket", "v2", ""); default: throw new ScmCommunicationException( - "Unexpected status code " + response.statusCode() + " " + response.toString()); + "Unexpected status code " + response.statusCode() + " " + response, + response.statusCode(), + "bitbucket"); } } } catch (IOException | InterruptedException | UncheckedIOException e) { - throw new ScmCommunicationException(e.getMessage(), e); + throw new ScmCommunicationException(e.getMessage(), e, "bitbucket"); } } diff --git a/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java b/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java index 623c977f916..c2d9a720100 100644 --- a/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java +++ b/wsmaster/che-core-api-factory-github-common/src/main/java/org/eclipse/che/api/factory/server/github/GithubApiClient.java @@ -300,11 +300,11 @@ private T executeRequest( throw new ScmUnauthorizedException(body, "github", "v2", ""); default: throw new ScmCommunicationException( - "Unexpected status code " + statusCode + " " + body, statusCode); + "Unexpected status code " + statusCode + " " + body, statusCode, "github"); } } } catch (IOException | InterruptedException | UncheckedIOException e) { - throw new ScmCommunicationException(e.getMessage(), e); + throw new ScmCommunicationException(e.getMessage(), e, "github"); } } diff --git a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabApiClient.java b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabApiClient.java index f378e145de1..e02005d2ad3 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabApiClient.java +++ b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabApiClient.java @@ -168,11 +168,12 @@ private T executeRequest( default: throw new ScmCommunicationException( "Unexpected status code " + response.statusCode() + " " + response, - response.statusCode()); + response.statusCode(), + "gitlab"); } } } catch (IOException | InterruptedException | UncheckedIOException e) { - throw new ScmCommunicationException(e.getMessage(), e); + throw new ScmCommunicationException(e.getMessage(), e, "gitlab"); } } diff --git a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/ApiExceptionMapper.java b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/ApiExceptionMapper.java index b8a1c1a3e48..f119ea40230 100644 --- a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/ApiExceptionMapper.java +++ b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/ApiExceptionMapper.java @@ -14,6 +14,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; import static org.eclipse.che.dto.server.DtoFactory.newDto; +import java.util.Collections; import java.util.Map; import org.eclipse.che.api.core.ApiException; import org.eclipse.che.api.core.BadRequestException; @@ -96,7 +97,10 @@ private static ApiException getApiException(Throwable throwable) { .withMessage( appendErrorMessage( "Error occurred during SCM communication.", throwable.getMessage())) - .withErrorCode(404)); + .withErrorCode(404) + .withAttributes( + Collections.singletonMap( + "provider", ((ScmCommunicationException) throwable).getProvider()))); } } return null; diff --git a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/scm/exception/ScmCommunicationException.java b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/scm/exception/ScmCommunicationException.java index 6bfd7fa31f9..05272319b34 100644 --- a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/scm/exception/ScmCommunicationException.java +++ b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/scm/exception/ScmCommunicationException.java @@ -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/ @@ -14,21 +14,36 @@ /** Thrown when problem occurred during communication with scm provider */ public class ScmCommunicationException extends Exception { private int statusCode; + private String provider; public ScmCommunicationException(String message) { super(message); } - public ScmCommunicationException(String message, int statusCode) { + public ScmCommunicationException(String message, int statusCode, String provider) { super(message); this.statusCode = statusCode; + this.provider = provider; } public ScmCommunicationException(String message, Throwable cause) { super(message, cause); } + public ScmCommunicationException(String message, Throwable cause, String provider) { + super(message, cause); + this.provider = provider; + } + public int getStatusCode() { return statusCode; } + + public String getProvider() { + return provider; + } + + public void setProvider(String provider) { + this.provider = provider; + } }