mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
updated error handling
This commit is contained in:
parent
78847dd026
commit
be75c9a3e5
2 changed files with 16 additions and 5 deletions
|
@ -1,11 +1,22 @@
|
|||
const uuid = require("uuid");
|
||||
|
||||
class MonkeyError {
|
||||
constructor(status, message = "Internal Server Error", stack = null) {
|
||||
constructor(status, message, stack = null) {
|
||||
this.status = status ?? 500;
|
||||
this.errorID = uuid.v4();
|
||||
this.message =
|
||||
process.env.MODE === "dev" ? (stack ? String(stack) : message) : message;
|
||||
let errorID = uuid.v4();
|
||||
if (this.status === 500) {
|
||||
this.message =
|
||||
process.env.MODE === "dev"
|
||||
? String(stack)
|
||||
: "Internal Server Error " + errorID;
|
||||
} else {
|
||||
this.message =
|
||||
process.env.MODE === "dev"
|
||||
? stack
|
||||
? String(stack)
|
||||
: message
|
||||
: message;
|
||||
}
|
||||
console.log(`ErrorID: ${this.errorID} logged...`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ app.use("/result", resultRouter);
|
|||
|
||||
app.use(function (e, req, res, next) {
|
||||
console.log("Error", e);
|
||||
let monkeyError = new MonkeyError(e.status, undefined, e.stack);
|
||||
let monkeyError = new MonkeyError(e.status, e.message, e.stack);
|
||||
return res.status(e.status || 500).json(monkeyError);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue