vertx-web
vertx-web copied to clipboard
New web client expectation, result type differ from error type
Switching to new web client expectation ( #2607 ) occurre bug when body codec response is set.
Response is decoded prior to check expecting and result to a DecodedException
Version Vertx 4.5.8
Do you have a reproducer?
@Test
public void newExpect() throws Exception {
UUID uuid = UUID.randomUUID();
int statusCode = 400;
Expectation<HttpResponseHead> expectation = HttpResponseExpectation.SC_SUCCESS
.wrappingFailure((head, err) -> new CustomException(uuid, String.valueOf(head.statusCode())));
server.requestHandler(request -> request.response()
.setStatusCode(statusCode)
.end("{}"));
startServer();
HttpRequest<Integer> request = webClient
.get("/test")
.as(json(Integer.class));
request.send().expecting(expectation).onComplete(ar -> {
Throwable cause = ar.cause();
assertThat(cause, instanceOf(CustomException.class));
testComplete();
});
await();
}
@Test
public void oldExpect() throws Exception {
UUID uuid = UUID.randomUUID();
int statusCode = 400;
server.requestHandler(request -> request.response()
.setStatusCode(statusCode)
.end("{}"));
startServer();
HttpRequest<Integer> request = webClient
.get("/test")
.as(json(Integer.class));
final ResponsePredicate predicate = ResponsePredicate.create(ResponsePredicate.SC_SUCCESS, result ->
new CustomException(uuid, String.valueOf(result.response().statusCode()))
);
request.expect(predicate).send().onComplete(ar -> {
Throwable cause = ar.cause();
assertThat(cause, instanceOf(CustomException.class));
testComplete();
});
await();
}
same with JsonObject vs JsonArray, etc ..