Skip to content

Commit 8aec1d0

Browse files
committed
fix: check null categories
1 parent cd872f6 commit 8aec1d0

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/service/post/post-cat.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export namespace PostCatService {
2121
try {
2222
const resp = await req.getAll()
2323
const { categories } = <{ categories: PostCat[] }>JSON.parse(resp)
24+
if (categories == null) return []
2425
return categories.map(x => Object.assign(new PostCat(), x))
2526
} catch (e) {
2627
if (await UserService.hasBlog()) void Alert.err(`查询随笔分类失败: ${<string>e}`)
@@ -60,6 +61,7 @@ export namespace PostCatService {
6061
try {
6162
const resp = await req.getOne(parentId)
6263
const { categories } = <{ categories: PostCat[] }>JSON.parse(resp)
64+
if (categories == null) return []
6365
return categories.map(x => Object.assign(new PostCat(), x))
6466
} catch (e) {
6567
if (await UserService.hasBlog()) void Alert.err(`查询随笔分类失败: ${<string>e}`)

0 commit comments

Comments
 (0)