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);
}
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);
}
}
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);
}
}
Aggregations