furo 2021-11-05 14:00:53 +01:00
commit 69313e86c7
3 changed files with 42 additions and 6 deletions

View File

@ -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 })
}
}

View File

@ -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" })
}
)

22
views/pages/error.njk Normal file
View File

@ -0,0 +1,22 @@
{% extends "../templates/basic.njk" %}
{% block body %}
<main class="flex-container">
<div class="error">
<h1>
We are really sorry about this...
</h1>
<p>
There seems as if you've ran into an error...
<br> <br>
</p>
<h6>
Reported error:
</h6>
<code>
{{ data.error }}
</code>
</div>
</main>
{% endblock %}