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 a18ae884d2..dae10eb58d 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 a92c2b8b61..6cf5383c71 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 764884f19f..6f0ef8a23f 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 623c977f91..c2d9a72010 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 f378e145de..e02005d2ad 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 b8a1c1a3e4..f119ea4023 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 6bfd7fa31f..05272319b3 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; + } }