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 https://github.com/halo-dev/halo/issues/7409

#### Does this PR introduce a user-facing change?

```release-note
修复访问不存在的分类或者文章页面时始终抛出异常的问题
```
pull/7423/head
John Niang 2025-05-09 15:11:48 +08:00 committed by GitHub
parent 5c8f86e917
commit 8a68a59ea5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -55,9 +55,7 @@ public class ThemeCompositeRouterFunction implements RouterFunction<ServerRespon
@NonNull
public Mono<HandlerFunction<ServerResponse>> route(@NonNull ServerRequest request) {
return Flux.fromIterable(cachedRouters)
.concatMap(routerFunction -> routerFunction.route(request)
.filterWhen(handle -> handle.handle(request).hasElement())
)
.concatMap(routerFunction -> routerFunction.route(request))
.next();
}

View File

@ -39,6 +39,7 @@ import run.halo.app.core.extension.content.Post;
import run.halo.app.extension.MetadataUtil;
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.extension.index.query.QueryFactory;
import run.halo.app.infra.exception.NotFoundException;
import run.halo.app.infra.utils.JsonUtils;
import run.halo.app.theme.DefaultTemplateEnum;
import run.halo.app.theme.ViewNameResolver;
@ -105,7 +106,8 @@ public class PostRouteFactory implements RouteFactory {
HandlerFunction<ServerResponse> handlerFunction() {
return request -> {
PostPatternVariable patternVariable = PostPatternVariable.from(request);
return postResponse(request, patternVariable);
return postResponse(request, patternVariable)
.switchIfEmpty(Mono.error(() -> new NotFoundException("Post not found.")));
};
}