0

I have a request like this:

    public ResponseEntity<JsonNode> test(String id) {
    return WebClient
        .create("http://localhost:8090/database/api")
        .get()
        .uri("/test/{id}", id)
        .accept(MediaType.APPLICATION_JSON)
        .exchange()
        .flatMap(resp -> resp.toEntity(JsonNode.class))
        .block();
}

Works fine when request is ok (HttpStatus code 200)

How I return the same Body and HttpStatus Code when error happen

lucianojs
  • 165
  • 1
  • 8

1 Answers1

0

I solved it this way:

    public ResponseEntity<JsonNode> test(String id) {
    return WebClient.create("http://localhost:8090/database/api").get().uri("/test/{id}", id)
            .accept(MediaType.ALL).exchange()
            .block()
            .toEntity(JsonNode.class)
            .block();
}

The problem was the lack of a block () after exchange().

lucianojs
  • 165
  • 1
  • 8