Make get_session() readonly and throw an exception if session cannot be found rather...
[ndcode_site.git] / _lib / get_navigation.jst
index 17ec41b..fc0de7c 100644 (file)
@@ -1,8 +1,24 @@
+let jst_server = (await import('@ndcode/jst_server')).default
+
 return async (root, component_names) => {
   let p = await root.get('navigation')
+  if (p === undefined)
+    throw new jst_server.Problem(
+      'Navigation error',
+      'Please import the navigation tree into the database.',
+      508
+    )
   for (let i = 0; i < component_names.length; ++i) {
     let children = await p.get('children')
     p = await children.get(component_names[i])
+    if (p === undefined)
+      throw new jst_server.Problem(
+        'Navigation error',
+        `Can't find the path "${
+          component_names.slice(0, i + 1).map(name => '/' + name).join('')
+        }" in the navigation tree.`,
+        508
+      )
   }
   return p
 }