public static EndpointResponse mapException(final Throwable exception) {
    if (exception instanceof KsqlRestException) {
      final KsqlRestException restException = (KsqlRestException) exception;
      return restException.getResponse();
    }
    return EndpointResponse.create()
        .status(INTERNAL_SERVER_ERROR.code())
        .type("application/json")
        .entity(new KsqlErrorMessage(Errors.ERROR_CODE_SERVER_ERROR, exception))
        .build();
  }
@Test
  public void shouldReturnCorrectResponseForUnspecificException() {
    final EndpointResponse response = OldApiUtils
        .mapException(new Exception("error msg"));
    assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class));
    final KsqlErrorMessage errorMessage = (KsqlErrorMessage) response.getEntity();
    assertThat(errorMessage.getMessage(), equalTo("error msg"));
    assertThat(errorMessage.getErrorCode(), equalTo(Errors.ERROR_CODE_SERVER_ERROR));
    assertThat(response.getStatus(), equalTo(INTERNAL_SERVER_ERROR.code()));
  }