Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified deploy-prod.sh
100644 → 100755
Empty file.
Empty file modified deploy-sandbox.sh
100644 → 100755
Empty file.
Empty file modified install.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions server/server/database/db_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
users: "users",
project_coaches: "project_coaches",
sponsors: "sponsors",
error_log: "error_log",
},
senior_project_proposal_keys: {
title: "Title",
Expand Down
3 changes: 2 additions & 1 deletion server/server/database/table_sql/create_all_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
.read table_sql/time_log.sql
.read table_sql/users.sql
.read table_sql/sponsor_notes.sql
.read table_sql/page_html.sql
.read table_sql/page_html.sql
.read table_sql/error_log.sql
8 changes: 8 additions & 0 deletions server/server/database/table_sql/error_log.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE error_log (
error_log_id INTEGER PRIMARY KEY AUTOINCREMENT, -- internal id for this row
error_datetime DATETIME DEFAULT CURRENT_TIMESTAMP,
status_code INTEGER, -- error code
user_role TEXT, -- role of the user that caused the error (if any)
url TEXT, -- URL that caused the error
stack_trace TEXT -- stack trace (if any)
);
25 changes: 24 additions & 1 deletion server/server/error_handler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
// This is a general purpose error handler for the backend,
// when the backend encounters errors this handler redirects to an error page where necessary next steps can be taken.

const DBHandler = require("./database/db");
const DB_CONFIG = require("./database/db_config");
let db = new DBHandler();

function errorHandler(err, req, res, next) {
console.error("\n CAUGHT ERROR: ", err, "\n");
// Send the error to the client so that error can be displayed on error page

if (!err.statusCode) err.statusCode = 500;
if (!err.message) err.message = "Internal Server Error";

let error_sql = `
INSERT INTO ${DB_CONFIG.tableNames.error_log}
(error_datetime, status_code, user_role, url, stack_trace)
VALUES (datetime('now'), ?, ?, ?, ?);
`;

let values = [
err.statusCode,
req.user ? req.user.type : "unknown",
req.url,
err.stack ? err.stack : "no stack trace",
];

db.query(error_sql, values);

res.status(err.statusCode).json({
error: err.message || "Internal Server Error",
error: err.message,
statusCode: err.statusCode,
user_role: req.user.type,
url: req.url,
Expand Down
35 changes: 35 additions & 0 deletions server/server/routing/db_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,41 @@ module.exports = (db) => {
});
}

// get error logs
db_router.get("/getAllErrorLogs", [UserAuth.isAdmin], (req, res, next) => {
const getErrorLogsQuery = `
SELECT * FROM ${DB_CONFIG.tableNames.error_log} ORDER BY error_log_id ASC
`;
db.query(getErrorLogsQuery)
.then((errorLogs) => {
res.send(errorLogs);
})
.catch((err) => {
const error = new Error(err);
error.statusCode = 500;
return next(error);
});
});

db_router.delete(
"/removeErrorLog/:id",
[UserAuth.isAdmin],
(req, res, next) => {
const deleteErrorLogQuery = `
DELETE FROM ${DB_CONFIG.tableNames.error_log} WHERE error_log_id = ?
`;
db.query(deleteErrorLogQuery, [req.params.id])
.then(() => {
res.status(200).send();
})
.catch((err) => {
const error = new Error(err);
error.statusCode = 500;
return next(error);
});
},
);

db_router.get(
"/selectAllSponsorInfo",
[UserAuth.isCoachOrAdmin],
Expand Down
Empty file modified start.sh
100644 → 100755
Empty file.
Empty file modified stop.sh
100644 → 100755
Empty file.
Loading