use of io.airlift.http.client.UnexpectedResponseException in project trino by trinodb.
the class TestQueryResource method testGetQueryInfoDispatchFailure.
@Test
public void testGetQueryInfoDispatchFailure() {
String queryId = runToCompletion("SELECT");
QueryInfo info = getQueryInfo(queryId);
assertFalse(info.isScheduled());
assertNotNull(info.getFailureInfo());
assertEquals(info.getFailureInfo().getErrorCode(), SYNTAX_ERROR.toErrorCode());
server.getAccessControl().deny(privilege("query", VIEW_QUERY));
try {
assertThatThrownBy(() -> getQueryInfo(queryId)).isInstanceOf(UnexpectedResponseException.class).matches(throwable -> ((UnexpectedResponseException) throwable).getStatusCode() == 403);
} finally {
server.getAccessControl().reset();
}
}
use of io.airlift.http.client.UnexpectedResponseException in project trino by trinodb.
the class PinotClient method doHttpActionWithHeadersJson.
protected <T> T doHttpActionWithHeadersJson(Request.Builder requestBuilder, Optional<String> requestBody, JsonCodec<T> codec, Multimap<String, String> additionalHeaders) {
requestBuilder.addHeaders(additionalHeaders);
requestBuilder.setHeader(ACCEPT, APPLICATION_JSON);
if (requestBody.isPresent()) {
requestBuilder.setHeader(CONTENT_TYPE, APPLICATION_JSON);
requestBuilder.setBodyGenerator(StaticBodyGenerator.createStaticBodyGenerator(requestBody.get(), StandardCharsets.UTF_8));
}
Request request = requestBuilder.build();
JsonResponseHandler<T> responseHandler = createJsonResponseHandler(codec);
T response = null;
try {
response = httpClient.execute(request, responseHandler);
} catch (UnexpectedResponseException e) {
throw new PinotException(PinotErrorCode.PINOT_HTTP_ERROR, Optional.empty(), format("Unexpected response status: %d for request %s to url %s, with headers %s, full response %s", e.getStatusCode(), requestBody.orElse(""), request.getUri(), request.getHeaders(), response));
}
return response;
}
Aggregations