public static <R> RestResponse<R> of(final KsqlErrorMessage errorMessage) { return erroneous(errorMessage); }
private static <T> RestResponse<T> createErrorResponse( final String path, final Response response) { final KsqlErrorMessage errorMessage = response.readEntity(KsqlErrorMessage.class); if (errorMessage != null) { return RestResponse.erroneous(errorMessage); } if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { return RestResponse.erroneous(404, "Path not found. Path='" + path + "'. " + "Check your ksql http url to make sure you are connecting to a ksql server."); } if (response.getStatus() == Status.UNAUTHORIZED.getStatusCode()) { return RestResponse.erroneous(UNAUTHORIZED_ERROR_MESSAGE); } if (response.getStatus() == Status.FORBIDDEN.getStatusCode()) { return RestResponse.erroneous(FORBIDDEN_ERROR_MESSAGE); } return RestResponse.erroneous( Errors.toErrorCode(response.getStatus()), "The server returned an unexpected error."); }
@Test public void shouldPrintErrorOnErrorResponseFromRestClient() { expect(restClient.makeRootRequest()).andReturn(RestResponse.erroneous( Errors.ERROR_CODE_SERVER_ERROR, "it is broken")); replay(restClient); command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal); assertThat(out.toString(), containsString("it is broken")); }
@Test public void shouldPrintErrorOnUnsupportedAPI() throws Exception { givenRunInteractivelyWillExit(); final KsqlRestClient mockRestClient = EasyMock.mock(KsqlRestClient.class); EasyMock.expect(mockRestClient.makeRootRequest()).andReturn( RestResponse.erroneous( new KsqlErrorMessage( Errors.toErrorCode(NOT_ACCEPTABLE.getStatusCode()), "Minimum supported client version: 1.0"))); EasyMock.expect(mockRestClient.getServerInfo()).andReturn( RestResponse.of(new ServerInfo("1.x", "testClusterId", "testServiceId"))); EasyMock.expect(mockRestClient.getServerAddress()).andReturn(new URI("http://someserver:8008")); EasyMock.replay(mockRestClient); new Cli(1L, 1L, mockRestClient, console) .runInteractively(); Assert.assertThat( terminal.getOutputString(), containsString("This CLI version no longer supported")); Assert.assertThat( terminal.getOutputString(), containsString("Minimum supported client version: 1.0")); }