mirror of https://github.com/halo-dev/halo
fix: NPE when navigation post not exists (#3847)
#### What type of PR is this? /kind bug /area core /milestone 2.5.x #### What this PR does / why we need it: 修复文章上下篇数据查询 NPE 问题 #### Does this PR introduce a user-facing change? ```release-note None ```pull/3852/head v2.5.0-rc.1
parent
18c0ced64e
commit
ed3a618ed4
|
@ -22,6 +22,7 @@ import run.halo.app.content.PostService;
|
||||||
import run.halo.app.core.extension.content.Post;
|
import run.halo.app.core.extension.content.Post;
|
||||||
import run.halo.app.extension.ListResult;
|
import run.halo.app.extension.ListResult;
|
||||||
import run.halo.app.extension.ReactiveExtensionClient;
|
import run.halo.app.extension.ReactiveExtensionClient;
|
||||||
|
import run.halo.app.extension.exception.ExtensionNotFoundException;
|
||||||
import run.halo.app.infra.utils.HaloUtils;
|
import run.halo.app.infra.utils.HaloUtils;
|
||||||
import run.halo.app.theme.finders.Finder;
|
import run.halo.app.theme.finders.Finder;
|
||||||
import run.halo.app.theme.finders.PostFinder;
|
import run.halo.app.theme.finders.PostFinder;
|
||||||
|
@ -85,9 +86,9 @@ public class PostFinderImpl implements PostFinder {
|
||||||
postPreviousNextPair(postNames, currentName);
|
postPreviousNextPair(postNames, currentName);
|
||||||
String previousPostName = previousNextPair.getLeft();
|
String previousPostName = previousNextPair.getLeft();
|
||||||
String nextPostName = previousNextPair.getRight();
|
String nextPostName = previousNextPair.getRight();
|
||||||
return getByName(previousPostName)
|
return fetchByName(previousPostName)
|
||||||
.doOnNext(builder::previous)
|
.doOnNext(builder::previous)
|
||||||
.then(getByName(nextPostName))
|
.then(fetchByName(nextPostName))
|
||||||
.doOnNext(builder::next)
|
.doOnNext(builder::next)
|
||||||
.thenReturn(builder);
|
.thenReturn(builder);
|
||||||
})
|
})
|
||||||
|
@ -95,6 +96,14 @@ public class PostFinderImpl implements PostFinder {
|
||||||
.defaultIfEmpty(NavigationPostVo.empty());
|
.defaultIfEmpty(NavigationPostVo.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Mono<PostVo> fetchByName(String name) {
|
||||||
|
if (StringUtils.isBlank(name)) {
|
||||||
|
return Mono.empty();
|
||||||
|
}
|
||||||
|
return getByName(name)
|
||||||
|
.onErrorResume(ExtensionNotFoundException.class::isInstance, (error) -> Mono.empty());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<ListedPostVo> listAll() {
|
public Flux<ListedPostVo> listAll() {
|
||||||
return client.list(Post.class, FIXED_PREDICATE, defaultComparator())
|
return client.list(Post.class, FIXED_PREDICATE, defaultComparator())
|
||||||
|
|
Loading…
Reference in New Issue