mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-06 01:09:02 +00:00
Improve null-safety of module/spring-boot-webflux
See gh-46926
This commit is contained in:
+2
-2
@@ -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<>(
|
||||
|
||||
+6
-1
@@ -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<ServerResponse> getErrorMono(ServerRequest request) {
|
||||
Throwable error = getError(request);
|
||||
return (error != null) ? Mono.error(error) : Mono.empty();
|
||||
}
|
||||
|
||||
private List<String> getData(int errorStatus) {
|
||||
List<String> data = new ArrayList<>();
|
||||
data.add("error/" + errorStatus);
|
||||
|
||||
Reference in New Issue
Block a user