Skip to content

Commit

Permalink
adds catch for malformed topic URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
davelandry committed Apr 25, 2019
1 parent a13cdd5 commit 5e0f0e2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/mortarRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,16 @@ module.exports = function(app) {
.catch(() => []);
let topic = topics.find(t => t.section.profile.slug === slug);
topic = varSwapRecursive(topic, formatterFunctions, variables, req.query);
topic.profile = topic.section.profile.slug;
topic.section = topic.section.slug;

if (topic.section) {
topic.profile = topic.section.profile.slug;
topic.section = topic.section.slug;
}
else {
topic.profile = slug;
topic.section = "";
console.error(`[topic] unable to fetch section for /api/topic/${slug}/${pid}/${topicId}`);
}

if (topic.subtitles) topic.subtitles.sort(sorter);
if (topic.selectors) topic.selectors.sort(sorter);
Expand Down

0 comments on commit 5e0f0e2

Please sign in to comment.