public static <T> RestResponse<T> toRestResponse(
      final ResponseWithBody resp,
      final String path,
      final Function<ResponseWithBody, T> mapper
  ) {
    final int statusCode = resp.getResponse().statusCode();
    return statusCode == OK.code()
        ? RestResponse.successful(statusCode, mapper.apply(resp))
        : createErrorResponse(path, resp);
  }
@Test
  public void shouldCreateRestResponseFromUnauthorizedResponse() {
    // Given:
    when(httpClientResponse.statusCode()).thenReturn(UNAUTHORIZED.code());

    // When:
    final RestResponse<KsqlEntityList> restResponse =
        KsqlClientUtil.toRestResponse(response, PATH, mapper);

    // Then:
    assertThat("is erroneous", restResponse.isErroneous());
    assertThat(restResponse.getStatusCode(), is(UNAUTHORIZED.code()));
    assertThat(restResponse.getErrorMessage().getMessage(),
        containsString("Could not authenticate successfully with the supplied credential"));
  }