Abhishek Wadhwa
Abhishek Wadhwa

Reputation: 53

Fetch Request body in webclient when using Mono zip to identify which request fails

I am using webclient to call 3 different external APIs in parallel using Mono zip. Now, if any error occurs in any of the API call, I have handled it through a common exception handler using ExchangeFilterFunction. Now, I want to know which particular request fails(out of 3 external API calls) ? Is there any way I can identify that? I also want to append the 'input request body' with the exception response I got from the API call. Can I fetch the request body for which the API Fails (in filter itself)?

Upvotes: 0

Views: 149

Answers (1)

Alex
Alex

Reputation: 5944

In the ExchangeFilterFunction you have access to the request. You could "decorate" your request with some identifier and then use it to resolve the client.

  1. You could add some request header to identify the client.
  2. To keep it internal, you could use request attributes of the WebClient and then read it from the request object
webClient.get()
       .uri("...")
       .attributes((attributes) -> attributes.put("internal_client_id", clientId))

Upvotes: 0

Related Questions