Skip to content

Commit 8a68a59

Browse files
authored
Fix potential twice theme route handler invocations (#7419)
#### What type of PR is this? /kind bug /area core /milestone 2.20.x #### What this PR does / why we need it: 1. This PR removes duplicate invocations while resolving handler functions of theme. 2. Throw NotFoundException while post was not found. #### Which issue(s) this PR fixes: Fixes #7409 #### Does this PR introduce a user-facing change? ```release-note 修复访问不存在的分类或者文章页面时始终抛出异常的问题 ```
1 parent 5c8f86e commit 8a68a59

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

application/src/main/java/run/halo/app/theme/router/ThemeCompositeRouterFunction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ public class ThemeCompositeRouterFunction implements RouterFunction<ServerRespon
5555
@NonNull
5656
public Mono<HandlerFunction<ServerResponse>> route(@NonNull ServerRequest request) {
5757
return Flux.fromIterable(cachedRouters)
58-
.concatMap(routerFunction -> routerFunction.route(request)
59-
.filterWhen(handle -> handle.handle(request).hasElement())
60-
)
58+
.concatMap(routerFunction -> routerFunction.route(request))
6159
.next();
6260
}
6361

application/src/main/java/run/halo/app/theme/router/factories/PostRouteFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import run.halo.app.extension.MetadataUtil;
4040
import run.halo.app.extension.ReactiveExtensionClient;
4141
import run.halo.app.extension.index.query.QueryFactory;
42+
import run.halo.app.infra.exception.NotFoundException;
4243
import run.halo.app.infra.utils.JsonUtils;
4344
import run.halo.app.theme.DefaultTemplateEnum;
4445
import run.halo.app.theme.ViewNameResolver;
@@ -105,7 +106,8 @@ HandlerFunction<ServerResponse> queryParamHandlerFunction(PatternParser paramPre
105106
HandlerFunction<ServerResponse> handlerFunction() {
106107
return request -> {
107108
PostPatternVariable patternVariable = PostPatternVariable.from(request);
108-
return postResponse(request, patternVariable);
109+
return postResponse(request, patternVariable)
110+
.switchIfEmpty(Mono.error(() -> new NotFoundException("Post not found.")));
109111
};
110112
}
111113

0 commit comments

Comments
 (0)