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 6f1997f commit 1b4b316
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ private <T> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ private <T> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,13 @@ private <T> 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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ private <T> 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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ private <T> 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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
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 All @@ -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;
}
}

0 comments on commit 1b4b316

Please sign in to comment.