Webflux collect errors from list?

102 Views Asked by At

I have a List<String> myList. The code looks like:

Flux.fromIterable(myList)
  .distinct()
  .flatMap(id -> mysvc.getItem(id)
        .switchIfEmpty(Mono.error(...))))

Note that mysvc is returning a Mono<Item> and the .switchIfEmpty is attached to THAT CALL, NOT the flatmap as mysvc will return a Mono.empty() if id is invalid.

Right now, it is throwing an error if an id is invalid as expected, but it throws them one at a time. If you have 2 errors, you'll only see the first one until you fix it, and then you'll see the next one and so on.

Ideally, I'd like to somehow collect all the bad ids and display a single error message otherwise return the Flux<Item>.

0

There are 0 best solutions below