Search in sources :

Example 16 with KsqlErrorMessage

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();
}
Also used : NotUpToBoundException(io.confluent.ksql.execution.streams.materialization.ks.NotUpToBoundException) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Example 17 with KsqlErrorMessage

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();
    }
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Example 18 with KsqlErrorMessage

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);
}
Also used : KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 19 with KsqlErrorMessage

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"));
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 20 with KsqlErrorMessage

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());
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Aggregations

KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)43 Test (org.junit.Test)35 EndpointResponse (io.confluent.ksql.rest.EndpointResponse)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)5 KsqlStatementErrorMessage (io.confluent.ksql.rest.entity.KsqlStatementErrorMessage)5 IntegrationTest (io.confluent.common.utils.IntegrationTest)4 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)4 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)3 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)3 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)3 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)3 MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)2 ListQueries (io.confluent.ksql.parser.tree.ListQueries)2 Query (io.confluent.ksql.parser.tree.Query)2 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)2 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)2 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)2