summaryrefslogtreecommitdiff
path: root/utils.js
diff options
context:
space:
mode:
authorCarson Fleming <cflems@cflems.net>2023-10-19 03:17:21 -0400
committerCarson Fleming <cflems@cflems.net>2023-10-19 03:17:21 -0400
commitc6d0cd3fca3cc9cacdb4c5a88797d00ae5560841 (patch)
tree061a3a5bbaeb5d99086ddd3a93ba20e6a2667126 /utils.js
parent85f217f63e248ae0df44368a6a0d03620955f170 (diff)
downloadfle.ms-c6d0cd3fca3cc9cacdb4c5a88797d00ae5560841.tar.gz
Dream up a style for the frontend
Diffstat (limited to 'utils.js')
-rw-r--r--utils.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/utils.js b/utils.js
index 7ea6b42..bd03888 100644
--- a/utils.js
+++ b/utils.js
@@ -2,11 +2,25 @@ const path = require('path');
const config = require('./config.js');
const helperFunctions = {
+ sendFile : function (res, fileName) {
+ res.sendFile(fileName, {
+ root: path.join(__dirname)
+ }, err => {
+ if (!err) return;
+ utils.sendNotFoundError(res)
+ });
+ },
sendNotFoundError : function (res) {
- res.status(404).sendFile('static/notfound.html', {root: path.join(__dirname)},
- err => res.json(
- {status: "ERROR", statusCode: 404, errorType: "NOT FOUND", errorMessage: "Not Found"}
- ));
+ if (!res.headersSent) res.status(404);
+ const statusJson = {status: "ERROR", statusCode: 404, errorType: "NOT FOUND", errorMessage: "Not Found"};
+ res.sendFile('static/notfound.html', {root: path.join(__dirname)},
+ err => {
+ if (!err) return;
+
+ console.error('[express] Encountered an error:', err);
+ if (!res.headersSent) res.json(statusJson);
+ else res.send(JSON.stringify(statusJson));
+ });
},
sendBadRequestError : function (res, errorMessage) {
res.status(400).json({status: "ERROR", statusCode: 400, errorType: "BAD REQUEST", errorMessage});