Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Error Handling in Reactive Flows

In some workflows, it is essential that interrupted sequences are flagged proactively as errors rather than simply returning empty Mono or Flux streams. This enables upstream callers to register errors and to know that a flow was not complete. In workflow scenarios, use cases that cause premature termination of the stream should explicitly return an error object and not just a .empty()

Example handling from BorrowingAgencyService:

            return Mono.from(clusterRecordRepository.findById(bibClusterId))
                            .flatMap(clusterRecord -> Mono.from(bibRepository.findById(clusterRecord.getSelectedBib())))
                            .map(this::extractBibData)
                            .flatMap(hostLmsClient::createBib)
                            .map(patronRequest::setLocalBibId)
                            .switchIfEmpty(Mono.error(new RuntimeException("Failed to create virtual bib.")))
                            .map(pr -> Tuples.of(pr, patronIdentity, hostLmsClient, supplierRequest));
  • No labels