Search in sources :

Example 16 with ScmItemNotFoundException

use of org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException in project devspaces-images by redhat-developer.

the class DevfileToApiExceptionMapperTest method shouldReturnBadrequestExceptionWhenCauseIsOtherException.

@Test
public void shouldReturnBadrequestExceptionWhenCauseIsOtherException() {
    ScmItemNotFoundException itemNotFoundException = new ScmItemNotFoundException("unknown");
    ApiException exception = DevfileToApiExceptionMapper.toApiException(new DevfileException("text", itemNotFoundException));
    assertTrue(exception instanceof BadRequestException);
}
Also used : ScmItemNotFoundException(org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) ApiException(org.eclipse.che.api.core.ApiException) Test(org.testng.annotations.Test)

Example 17 with ScmItemNotFoundException

use of org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException in project devspaces-images by redhat-developer.

the class GithubApiClient method executeRequest.

private <T> T executeRequest(HttpClient httpClient, HttpRequest request, Function<HttpResponse<InputStream>, T> responseConverter) throws ScmBadRequestException, ScmItemNotFoundException, ScmCommunicationException {
    try {
        HttpResponse<InputStream> response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
        LOG.trace("executeRequest={} response {}", request, response.statusCode());
        if (response.statusCode() == HTTP_OK) {
            return responseConverter.apply(response);
        } else if (response.statusCode() == HTTP_NO_CONTENT) {
            return null;
        } else {
            String body = CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
            switch(response.statusCode()) {
                case HTTP_BAD_REQUEST:
                    throw new ScmBadRequestException(body);
                case HTTP_NOT_FOUND:
                    throw new ScmItemNotFoundException(body);
                default:
                    throw new ScmCommunicationException("Unexpected status code " + response.statusCode() + " " + response.toString());
            }
        }
    } catch (IOException | InterruptedException | UncheckedIOException e) {
        throw new ScmCommunicationException(e.getMessage(), e);
    }
}
Also used : ScmItemNotFoundException(org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ScmBadRequestException(org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException)

Example 18 with ScmItemNotFoundException

use of org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException in project devspaces-images by redhat-developer.

the class HttpBitbucketServerApiClient method executeRequest.

private <T> T executeRequest(HttpClient httpClient, HttpRequest request, Function<InputStream, T> bodyConverter) throws ScmBadRequestException, ScmItemNotFoundException, ScmCommunicationException, ScmUnauthorizedException {
    try {
        HttpResponse<InputStream> response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
        LOG.trace("executeRequest={} response {}", request, response.statusCode());
        if (response.statusCode() == 200) {
            return bodyConverter.apply(response.body());
        } else if (response.statusCode() == 204) {
            return null;
        } else {
            String body = CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
            switch(response.statusCode()) {
                case HTTP_UNAUTHORIZED:
                    throw buildScmUnauthorizedException();
                case HTTP_BAD_REQUEST:
                    throw new ScmBadRequestException(body);
                case HTTP_NOT_FOUND:
                    throw new ScmItemNotFoundException(body);
                default:
                    throw new ScmCommunicationException("Unexpected status code " + response.statusCode() + " " + response.toString());
            }
        }
    } catch (IOException | InterruptedException | UncheckedIOException e) {
        throw new ScmCommunicationException(e.getMessage(), e);
    }
}
Also used : ScmItemNotFoundException(org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ScmBadRequestException(org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException)

Aggregations

ScmItemNotFoundException (org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException)18 ScmCommunicationException (org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException)16 ScmBadRequestException (org.eclipse.che.api.factory.server.scm.exception.ScmBadRequestException)14 IOException (java.io.IOException)10 UncheckedIOException (java.io.UncheckedIOException)10 InputStream (java.io.InputStream)8 InputStreamReader (java.io.InputStreamReader)8 ScmUnauthorizedException (org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException)8 BadRequestException (org.eclipse.che.api.core.BadRequestException)6 PersonalAccessToken (org.eclipse.che.api.factory.server.scm.PersonalAccessToken)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 URI (java.net.URI)4 HttpRequest (java.net.http.HttpRequest)4 List (java.util.List)4 OAuthToken (org.eclipse.che.api.auth.shared.dto.OAuthToken)4 ConflictException (org.eclipse.che.api.core.ConflictException)4 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 ServerException (org.eclipse.che.api.core.ServerException)4 UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)4