use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class QuerySubscriber method handleError.
@Override
public void handleError(final Throwable t) {
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(t);
for (Throwable s : t.getSuppressed()) {
if (s instanceof NotUpToBoundException) {
stringBuilder.append(" Failed to get value from materialized table, reason: " + "NOT_UP_TO_BOUND");
} else {
stringBuilder.append(s.getMessage());
}
}
final KsqlErrorMessage errorResponse = new KsqlErrorMessage(ERROR_CODE_SERVER_ERROR, stringBuilder.toString());
log.error("Error in processing query {}", stringBuilder);
queryStreamResponseWriter.writeError(errorResponse).end();
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class ServerStateHandler method handle.
@Override
public void handle(final RoutingContext routingContext) {
final Optional<EndpointResponse> response = serverState.checkReady();
if (response.isPresent()) {
final KsqlErrorMessage errorMsg = (KsqlErrorMessage) response.get().getEntity();
routingContext.fail(SERVICE_UNAVAILABLE.code(), new KsqlApiException(errorMsg.getMessage(), errorMsg.getErrorCode()));
} else {
routingContext.next();
}
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class ServerStateTest method shouldReturn503IfInitializing.
@Test
public void shouldReturn503IfInitializing() throws Exception {
// Given:
this.serverState.setInitializingReason(new KsqlErrorMessage(INITIALIZING_ERROR_CODE, INITIALIZING_MESSAGE));
// When/Then:
validateResponse(503, INITIALIZING_ERROR_CODE, INITIALIZING_MESSAGE);
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class KsqlClientTest method shouldHandleErrorMessageOnPostRequests.
@Test
public void shouldHandleErrorMessageOnPostRequests() {
// Given:
KsqlErrorMessage ksqlErrorMessage = new KsqlErrorMessage(40000, "ouch");
server.setResponseObject(ksqlErrorMessage);
server.setErrorCode(400);
// When:
KsqlTarget target = ksqlClient.target(serverUri);
RestResponse<KsqlEntityList> response = target.postKsqlRequest("sql", Collections.emptyMap(), Optional.of(123L));
// Then:
assertThat(response.getStatusCode(), is(400));
assertThat(response.getErrorMessage().getErrorCode(), is(40000));
assertThat(response.getErrorMessage().getMessage(), is("ouch"));
}
use of io.confluent.ksql.rest.entity.KsqlErrorMessage in project ksql by confluentinc.
the class KsqlClientUtilTest method shouldCreateRestResponseFromUnsuccessfulResponseWithMessage.
@Test
public void shouldCreateRestResponseFromUnsuccessfulResponseWithMessage() {
// Given:
KsqlErrorMessage errorMessage = new KsqlErrorMessage(12345, "foobar");
when(httpClientResponse.statusCode()).thenReturn(BAD_REQUEST.code());
when(response.getBody()).thenReturn(KsqlClientUtil.serialize(errorMessage));
// When:
final RestResponse<KsqlEntityList> restResponse = KsqlClientUtil.toRestResponse(response, PATH, mapper);
// Then:
assertThat("is erroneous", restResponse.isErroneous());
assertThat(restResponse.getStatusCode(), is(BAD_REQUEST.code()));
assertThat(restResponse.getErrorMessage(), is(errorMessage));
verify(mapper, never()).apply(any());
}
Aggregations