block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2

Viewed 667

I am quite new at reactive programming. I do call to an external api in this way:

ApiReponse apiResponse= client.post()
            .cookie(cookie.getName(), cookie.getValue())
            .bodyValue(body)
            .exchangeToMono(response -> {
                if (response.statusCode().isError()) {
                    return handleError(response, cookie.getValue());
                }
                return response.bodyToMono(ApiReponse .class);
            })
            .block();

The problem is that, if the response has an error, I get the following message on the console:

block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2

How can I handle this? I don't know if I am using the webclient in the proper way

0 Answers
Related