Rename Mono#otherwise[Empty] to switch[onError/IfEmpty]

Issue: SPR-15318
This commit is contained in:
Sebastien Deleuze
2017-04-13 15:30:21 +02:00
parent cec36fe784
commit e3fae2716e
19 changed files with 23 additions and 23 deletions

View File

@@ -125,7 +125,7 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware {
return Flux.fromIterable(this.handlerMappings)
.concatMap(mapping -> mapping.getHandler(exchange))
.next()
.otherwiseIfEmpty(Mono.error(HANDLER_NOT_FOUND_EXCEPTION))
.switchIfEmpty(Mono.error(HANDLER_NOT_FOUND_EXCEPTION))
.flatMap(handler -> invokeHandler(exchange, handler))
.flatMap(result -> handleResult(exchange, result));
}
@@ -141,7 +141,7 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware {
private Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
return getResultHandler(result).handleResult(exchange, result)
.otherwise(ex -> result.applyExceptionHandler(ex).flatMap(exceptionResult ->
.switchOnError(ex -> result.applyExceptionHandler(ex).flatMap(exceptionResult ->
getResultHandler(exceptionResult).handleResult(exchange, exceptionResult)));
}

View File

@@ -168,7 +168,7 @@ class DefaultRenderingResponseBuilder implements RenderingResponse.Builder {
return Flux.fromStream(viewResolverStream)
.concatMap(viewResolver -> viewResolver.resolveViewName(name(), locale))
.next()
.otherwiseIfEmpty(Mono.error(new IllegalArgumentException("Could not resolve view with name '" +
.switchIfEmpty(Mono.error(new IllegalArgumentException("Could not resolve view with name '" +
name() +"'")))
.flatMap(view -> view.render(model(), contentType, exchange));
}

View File

@@ -48,7 +48,7 @@ public interface RouterFunction<T extends ServerResponse> {
*/
default RouterFunction<T> and(RouterFunction<T> other) {
return request -> this.route(request)
.otherwiseIfEmpty(Mono.defer(() -> other.route(request)));
.switchIfEmpty(Mono.defer(() -> other.route(request)));
}
/**
@@ -63,7 +63,7 @@ public interface RouterFunction<T extends ServerResponse> {
default RouterFunction<?> andOther(RouterFunction<?> other) {
return request -> this.route(request)
.map(RouterFunctions::cast)
.otherwiseIfEmpty(
.switchIfEmpty(
Mono.defer(() -> other.route(request).map(RouterFunctions::cast)));
}

View File

@@ -234,7 +234,7 @@ public abstract class RouterFunctions {
.defaultIfEmpty(notFound())
.flatMap(handlerFunction -> wrapException(() -> handlerFunction.handle(request)))
.flatMap(response -> wrapException(() -> response.writeTo(exchange, strategies)))
.otherwise(ResponseStatusException.class,
.switchOnError(ResponseStatusException.class,
ex -> {
exchange.getResponse().setStatusCode(ex.getStatus());
if (ex.getMessage() != null) {

View File

@@ -276,7 +276,7 @@ public class ResourceWebHandler
public Mono<Void> handle(ServerWebExchange exchange) {
return getResource(exchange)
.otherwiseIfEmpty(Mono.defer(() -> {
.switchIfEmpty(Mono.defer(() -> {
logger.trace("No matching resource found - returning 404");
exchange.getResponse().setStatusCode(HttpStatus.NOT_FOUND);
return Mono.empty();

View File

@@ -159,7 +159,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
List<? extends Resource> locations, ResourceResolverChain chain) {
return chain.resolveResource(exchange, requestPath, locations)
.otherwiseIfEmpty(Mono.defer(() ->
.switchIfEmpty(Mono.defer(() ->
resolveVersionedResource(exchange, requestPath, locations, chain)));
}

View File

@@ -75,7 +75,7 @@ public class WebJarsResourceResolver extends AbstractResourceResolver {
List<? extends Resource> locations, ResourceResolverChain chain) {
return chain.resolveResource(exchange, requestPath, locations)
.otherwiseIfEmpty(Mono.defer(() -> {
.switchIfEmpty(Mono.defer(() -> {
String webJarsResourcePath = findWebJarResourcePath(requestPath);
if (webJarsResourcePath != null) {
return chain.resolveResource(exchange, webJarsResourcePath, locations);
@@ -91,7 +91,7 @@ public class WebJarsResourceResolver extends AbstractResourceResolver {
List<? extends Resource> locations, ResourceResolverChain chain) {
return chain.resolveUrlPath(resourceUrlPath, locations)
.otherwiseIfEmpty(Mono.defer(() -> {
.switchIfEmpty(Mono.defer(() -> {
String webJarResourcePath = findWebJarResourcePath(resourceUrlPath);
if (webJarResourcePath != null) {
return chain.resolveUrlPath(webJarResourcePath, locations);

View File

@@ -130,9 +130,9 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho
}
else {
Mono<?> mono = reader.readMono(bodyType, elementType, request, response, readHints);
mono = mono.otherwise(ex -> Mono.error(getReadError(bodyParameter, ex)));
mono = mono.switchOnError(ex -> Mono.error(getReadError(bodyParameter, ex)));
if (isBodyRequired || (adapter != null && !adapter.supportsEmpty())) {
mono = mono.otherwiseIfEmpty(Mono.error(getRequiredBodyError(bodyParameter)));
mono = mono.switchIfEmpty(Mono.error(getRequiredBodyError(bodyParameter)));
}
Object[] hints = extractValidationHints(bodyParameter);
if (hints != null) {

View File

@@ -103,7 +103,7 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr
handleResolvedValue(arg, namedValueInfo.name, parameter, model, exchange);
return arg;
})
.otherwiseIfEmpty(getDefaultValue(
.switchIfEmpty(getDefaultValue(
namedValueInfo, parameter, bindingContext, model, exchange));
}

View File

@@ -189,7 +189,7 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, Application
.then(() -> this.methodResolver.getRequestMappingMethod(handlerMethod)
.invoke(exchange, bindingContext)
.doOnNext(result -> result.setExceptionHandler(exceptionHandler))
.otherwise(exceptionHandler));
.switchOnError(exceptionHandler));
}
private Mono<HandlerResult> handleException(Throwable ex, HandlerMethod handlerMethod,

View File

@@ -193,7 +193,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport
}
return valueMono
.otherwiseIfEmpty(exchange.isNotModified() ? Mono.empty() : NO_VALUE_MONO)
.switchIfEmpty(exchange.isNotModified() ? Mono.empty() : NO_VALUE_MONO)
.flatMap(returnValue -> {
Mono<List<View>> viewsMono;