Skip to content

Commit 9f3e2b6

Browse files
committed
handle edge case
1 parent 7dd6c93 commit 9f3e2b6

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

middleware/learning-track.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,22 @@ module.exports = async (req, res, next) => {
2424

2525
if (guideIndex > 0) {
2626
const prevGuidePath = track.guides[guideIndex - 1]
27-
const { href, title } = await getLinkData(prevGuidePath, req.context, { title: true, intro: false })
27+
const result = await getLinkData(prevGuidePath, req.context, { title: true, intro: false })
28+
if (!result) return noTrack()
29+
30+
const href = result.href
31+
const title = result.title
2832
currentLearningTrack.prevGuide = { href, title }
2933
}
3034

3135
if (guideIndex < track.guides.length - 1) {
3236
const nextGuidePath = track.guides[guideIndex + 1]
33-
const { href, title } = await getLinkData(nextGuidePath, req.context, { title: true, intro: false })
37+
const result = await getLinkData(nextGuidePath, req.context, { title: true, intro: false })
38+
if (!result) return noTrack()
39+
40+
const href = result.href
41+
const title = result.title
42+
3443
currentLearningTrack.nextGuide = { href, title }
3544
}
3645

0 commit comments

Comments
 (0)