Handling reactive errors
As we have done before, any microservice needs to be built for failure, so when we create reactive microservices, we can handle any error gracefully. The Reactor Framework provides mechanisms that we need to understand to handle those errors. In this section, we learn how to use them to make our reactive microservice as good at handling errors as our non-reactive microservices.
Capturing errors on Handlers
When we create handlers, we may encounter errors, and those errors can be handled with one special method in any reactive publisher onErrorResume
. Let's modify our create
method in the CustomerHandler
class to understand how it works:
package com.microservices.chapter4 import org.springframework.http.HttpStatus import org.springframework.stereotype.Component import org.springframework.web.reactive.function.BodyInserters.fromObject import org.springframework.web.reactive.function.server.ServerRequest import org.springframework.web.reactive.function.server.ServerResponse...