Replace constant exceptions with inlined ones
Issue: SRP-17475
This commit is contained in:
@@ -142,16 +142,23 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware {
|
||||
@Override
|
||||
public Mono<Void> handle(ServerWebExchange exchange) {
|
||||
if (this.handlerMappings == null) {
|
||||
return Mono.error(HANDLER_NOT_FOUND_EXCEPTION);
|
||||
return createNotFoundError();
|
||||
}
|
||||
return Flux.fromIterable(this.handlerMappings)
|
||||
.concatMap(mapping -> mapping.getHandler(exchange))
|
||||
.next()
|
||||
.switchIfEmpty(Mono.error(HANDLER_NOT_FOUND_EXCEPTION))
|
||||
.switchIfEmpty(createNotFoundError())
|
||||
.flatMap(handler -> invokeHandler(exchange, handler))
|
||||
.flatMap(result -> handleResult(exchange, result));
|
||||
}
|
||||
|
||||
private <R> Mono<R> createNotFoundError() {
|
||||
return Mono.defer(() -> {
|
||||
Exception ex = new ResponseStatusException(HttpStatus.NOT_FOUND, "No matching handler");
|
||||
return Mono.error(ex);
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<HandlerResult> invokeHandler(ServerWebExchange exchange, Object handler) {
|
||||
if (this.handlerAdapters != null) {
|
||||
for (HandlerAdapter handlerAdapter : this.handlerAdapters) {
|
||||
|
||||
@@ -88,8 +88,6 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
|
||||
|
||||
private static final Set<HttpMethod> SUPPORTED_METHODS = EnumSet.of(HttpMethod.GET, HttpMethod.HEAD);
|
||||
|
||||
private static final Exception NOT_FOUND_EXCEPTION = new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ResourceWebHandler.class);
|
||||
|
||||
|
||||
@@ -324,7 +322,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
|
||||
return getResource(exchange)
|
||||
.switchIfEmpty(Mono.defer(() -> {
|
||||
logger.debug(exchange.getLogPrefix() + "Resource not found");
|
||||
return Mono.error(NOT_FOUND_EXCEPTION);
|
||||
return Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
}))
|
||||
.flatMap(resource -> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user