From 006446b7b0a78cc2f0485c438ca2523fb598235c Mon Sep 17 00:00:00 2001 From: hippoz Date: Fri, 2 Oct 2020 23:12:51 +0300 Subject: [PATCH] add error message page --- index.js | 8 ++++---- views/uploaderror.ejs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 views/uploaderror.ejs diff --git a/index.js b/index.js index 9f5a67d..8bfb5d6 100644 --- a/index.js +++ b/index.js @@ -77,11 +77,11 @@ app.post('/api/upload', (req, res) => { const password = req.body.password; if (config.passwords.indexOf(password) === -1) { - return res.status(401).send('Incorrect password.'); + return res.status(401).render('uploadfailed', { message: 'The password you entered is not correct.' }); } if (!req.files || Object.keys(req.files).length === 0) { - return res.status(400).send('No files were uploaded.'); + return res.status(400).render('uploadfailed', { message: 'You forgot to upload a file.' }); } const file = req.files.file; @@ -89,14 +89,14 @@ app.post('/api/upload', (req, res) => { fs.stat(filepath, (err) => { if(err == null) { - return res.status(400).send('File exists.'); + return res.status(400).render('uploadfailed', { message: 'A file with that name already exists.' }); } else if(err.code === 'ENOENT') { file.mv(filepath, (err) => { if (err) return res.status(500).send(err); res.render('uploaded', { file: { name: file.name } }); }); } else { - return res.sendStatus(500); + return res.status(500).render('uploadfailed', { message: 'Something went wrong.' });; } }); }); diff --git a/views/uploaderror.ejs b/views/uploaderror.ejs new file mode 100644 index 0000000..a2bfec9 --- /dev/null +++ b/views/uploaderror.ejs @@ -0,0 +1,13 @@ + + + + + + Error + + +

upload failed

+

i think

+

<%= message %>

+ + \ No newline at end of file