diff --git a/infrastructure/web/routes/error.js b/infrastructure/web/routes/error.js new file mode 100644 index 0000000..64bdb15 --- /dev/null +++ b/infrastructure/web/routes/error.js @@ -0,0 +1,21 @@ +const express = require('express') + +const router = new express.Router() +const config = require('../../../application/config') + +router.get( + '^/:404', + async (req, res) => { + res.render('error', { + title: "48hr.email | 404", + message: error.message, + status: 404, + address: req.params.address, + stack: error.stack, + madeby: config.branding[1], + madebysite: config.branding[2] + }) + } +) + +module.exports = router diff --git a/infrastructure/web/routes/inbox.js b/infrastructure/web/routes/inbox.js index e46647b..78f713c 100644 --- a/infrastructure/web/routes/inbox.js +++ b/infrastructure/web/routes/inbox.js @@ -44,10 +44,7 @@ router.get( madebysite: config.branding[2] }) } else { - next({ - message: 'This mail could not be found. It either does not exist or has been deleted from our servers!', - status: 404 - }) + res.redirect('/404') } } catch (error) { console.error('error while fetching one email', error) diff --git a/infrastructure/web/views/error.twig b/infrastructure/web/views/error.twig index 626a42d..a428599 100644 --- a/infrastructure/web/views/error.twig +++ b/infrastructure/web/views/error.twig @@ -1,9 +1,17 @@ {% extends 'layout.twig' %} {% block body %} -
Logout
+
+ + ← Return to inbox +
+ + Delete Email +
+ + Logout

{{message}}

-

{{error.status}}

-
{{error.stack}}
+

{{status}}

+
{{stack}}
{% endblock %} diff --git a/infrastructure/web/web.js b/infrastructure/web/web.js index 09531d4..3670769 100644 --- a/infrastructure/web/web.js +++ b/infrastructure/web/web.js @@ -11,6 +11,7 @@ const socketio = require('socket.io') const config = require('../../application/config') const inboxRouter = require('./routes/inbox') const loginRouter = require('./routes/login') +const errorRouter = require('./routes/error') const {sanitizeHtmlTwigFilter} = require('./views/twig-filters') // Init express middleware @@ -49,6 +50,7 @@ app.get('/', (req, res, _next) => { app.use('/', loginRouter) app.use('/inbox', inboxRouter) +app.use('/404', errorRouter) // Catch 404 and forward to error handler app.use((req, res, next) => {