mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-06 05:26:54 +08:00
inserting monkey error into the database later to avoid recursive errors
This commit is contained in:
parent
133ae13503
commit
5cfa792eb2
2 changed files with 10 additions and 13 deletions
|
@ -1,5 +1,4 @@
|
|||
const uuid = require("uuid");
|
||||
const { mongoDB } = require("../init/mongodb");
|
||||
|
||||
class MonkeyError {
|
||||
constructor(status, message, stack = null, uid) {
|
||||
|
@ -14,18 +13,6 @@ class MonkeyError {
|
|||
? String(message)
|
||||
: message
|
||||
: "Internal Server Error " + this.errorID;
|
||||
|
||||
console.log("Error", message, stack);
|
||||
if (process.env.MODE !== "dev" && this.status > 400) {
|
||||
mongoDB().collection("errors").insertOne({
|
||||
_id: this.errorID,
|
||||
timestamp: Date.now(),
|
||||
status: this.status,
|
||||
uid,
|
||||
message,
|
||||
stack,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,16 @@ app.use(function (e, req, res, next) {
|
|||
uid = req.decodedToken.uid;
|
||||
}
|
||||
let monkeyError = new MonkeyError(e.status, e.message, e.stack, uid);
|
||||
if (process.env.MODE !== "dev" && monkeyError.status > 400) {
|
||||
connectDB().collection("errors").insertOne({
|
||||
_id: monkeyError.errorID,
|
||||
timestamp: Date.now(),
|
||||
status: monkeyError.status,
|
||||
uid: monkeyError.uid,
|
||||
message: monkeyError.message,
|
||||
stack: monkeyError.stack,
|
||||
});
|
||||
}
|
||||
return res.status(e.status || 500).json(monkeyError);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue