diff --git a/module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/endpoint/web/AbstractWebFluxEndpointHandlerMapping.java b/module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/endpoint/web/AbstractWebFluxEndpointHandlerMapping.java index 683d181817f..a611702945a 100644 --- a/module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/endpoint/web/AbstractWebFluxEndpointHandlerMapping.java +++ b/module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/endpoint/web/AbstractWebFluxEndpointHandlerMapping.java @@ -433,8 +433,8 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi if (result instanceof Flux) { result = ((Flux) result).collectList(); } - return Mono.from(result) - .map(this::toResponseEntity) + Mono mono = (result != null) ? Mono.from(result) : Mono.empty(); + return mono.map(this::toResponseEntity) .onErrorMap(InvalidEndpointRequestException.class, (ex) -> new ResponseStatusException(HttpStatus.BAD_REQUEST, ex.getReason())) .defaultIfEmpty(new ResponseEntity<>( diff --git a/module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/autoconfigure/error/DefaultErrorWebExceptionHandler.java b/module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/autoconfigure/error/DefaultErrorWebExceptionHandler.java index ee0b2731c82..7c705c9ae3f 100644 --- a/module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/autoconfigure/error/DefaultErrorWebExceptionHandler.java +++ b/module/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/autoconfigure/error/DefaultErrorWebExceptionHandler.java @@ -130,10 +130,15 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa return Flux.just(getData(status).toArray(new String[] {})) .flatMap((viewName) -> renderErrorView(viewName, responseBody, errorAttributes)) .switchIfEmpty(this.errorProperties.getWhitelabel().isEnabled() - ? renderDefaultErrorView(responseBody, errorAttributes) : Mono.error(getError(request))) + ? renderDefaultErrorView(responseBody, errorAttributes) : getErrorMono(request)) .next(); } + private Mono getErrorMono(ServerRequest request) { + Throwable error = getError(request); + return (error != null) ? Mono.error(error) : Mono.empty(); + } + private List getData(int errorStatus) { List data = new ArrayList<>(); data.add("error/" + errorStatus);