diff --git a/libs/routex.js b/libs/routex.js index 1d5a333..fff35d4 100644 --- a/libs/routex.js +++ b/libs/routex.js @@ -1,10 +1,22 @@ export default function routex(req, res) { if (req.baseUrl === "/api") - return function(_, data, _2) { - res.json(data) + return function(_, data, success, __) { + if (success) + return res.json({ + success, + response: data + }) + + return res.json({ + success, + response: data.error + }) } - return function(template, data, options) { - res.render(template, { data, options }) + return function(template, data, success, options) { + if (success) + return res.render(template, { data, options }) + + return res.render("pages/error.njk", { data, options }) } } \ No newline at end of file diff --git a/routes/routes.js b/routes/routes.js index d171952..252e5f5 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -15,7 +15,7 @@ routes.get( '/maps', (req, res) => { const maps = wrapper.allMaps() - tx(req, res)('pages/maps.njk', { maps }, { currentSection: "maps" }) + tx(req, res)('pages/maps.njk', { maps }, true, { currentSection: "maps" }) } ) @@ -27,7 +27,9 @@ routes.get( const raceLeaderboard = wrapper.leaderboardRace(req.params.map, 1, 10) const teamLeaderboard = wrapper.leaderboardTeamrace(req.params.map, 1, 10) - tx(req, res)('pages/mapSingle.njk', { map, graphMap, raceLeaderboard, teamLeaderboard }, { currentSection: "maps" }) + const [success, error] = map ? [true, "No error!"] : [false, "Map not found!"] + + tx(req, res)('pages/mapSingle.njk', { map, graphMap, raceLeaderboard, teamLeaderboard, error }, success, { currentSection: "maps" }) } ) diff --git a/views/pages/error.njk b/views/pages/error.njk new file mode 100644 index 0000000..478b992 --- /dev/null +++ b/views/pages/error.njk @@ -0,0 +1,22 @@ +{% extends "../templates/basic.njk" %} + +{% block body %} +
+
+

+ We are really sorry about this... +

+

+ There seems as if you've ran into an error... +

+

+ +
+ Reported error: +
+ + {{ data.error }} + +
+
+{% endblock %} \ No newline at end of file