Skip to content
Advertisement

How i return Empty mono if the request doesn’t return error using webClient

i want to know how return a empty Mono when i use webClient, i have this code and it works when the request return a user.

JavaScript

Advertisement

Answer

First of all, don’t use block() if you really want to take full advantage of using reactive stack. With it you are blocking the thread to wait for a response, don’t do that. You must always handle Mono and Flux in your code instead. Something along the following lines:

JavaScript

You can then specify what you want to do if the response is 4XX or 5XX. Below the example for 5XX:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement