title: How to get service layer to return a Mono::error when it fetches nothing from database
body: <p>I am using this code block to retrieve some data from Couchbase, but when it fails to fetch anything it does not invoke the <code>onErrorResume</code> block. Is there a way I can make this code invoke <code>onErrorResume</code> when it fails to find a document matching the key?</p>
  
  <pre><code>return referenceService.getReferenceTable(referenceKey)
      .flatMap(referenceTable -&gt; {
          logger.info("reference table: {}", referenceTable.toString());
          Market market = getMarket(aggregate.getDate(), aggregate.getMarket(), referenceTable);
          aggregate.setMarket(market);
          return Mono.just(aggregate);
      })
      .onErrorResume(e -&gt; {
          logger.info("Error getting reference table");
          return Mono.error(e);
      });
  </code></pre>
  
  <p>The service layer being use looks like this:</p>
  
  <pre><code>@Service("referenceService")
  public class CouchbaseReferenceService implements ReferenceService {
  
      @Autowired
      private ReferenceRepository referenceRepository;
  
      @Override
      public Mono&lt;ReferenceTable&gt; getReferenceTable(String key) {
          return referenceRepository.getReferenceTable(key);
      }
  
  }
  </code></pre>