mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-08 00:14:07 +08:00
using monkey error
This commit is contained in:
parent
a7aa36c3fa
commit
5fd1121d7b
2 changed files with 7 additions and 13 deletions
|
|
@ -1,19 +1,11 @@
|
|||
const uuid = require("uuid");
|
||||
|
||||
class MonkeyError {
|
||||
status = 500;
|
||||
message = "Internal Server Error";
|
||||
errorID = "";
|
||||
|
||||
constructor(status, message, stack = null) {
|
||||
this.status = status;
|
||||
this.message =
|
||||
process.env.MODE === "DEVELOPMENT"
|
||||
? stack
|
||||
? String(stack)
|
||||
: message
|
||||
: message;
|
||||
constructor(status, message = "Internal Server Error", stack = null) {
|
||||
this.status = status ?? 500;
|
||||
this.errorID = uuid.v4();
|
||||
this.message =
|
||||
process.env.MODE === "dev" ? (stack ? String(stack) : message) : message;
|
||||
console.log(`ErrorID: ${this.errorID} logged...`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
const express = require("express");
|
||||
const { config } = require("dotenv");
|
||||
const path = require("path");
|
||||
const MonkeyError = require("./handlers/error");
|
||||
config({ path: path.join(__dirname, ".env") });
|
||||
|
||||
const cors = require("cors");
|
||||
|
|
@ -26,7 +27,8 @@ app.use("/result", resultRouter);
|
|||
|
||||
app.use(function (e, req, res, next) {
|
||||
console.log("Error", e);
|
||||
return res.status(e.status || 500).json(e || {});
|
||||
let monkeyError = new MonkeyError(e.status, undefined, e.stack);
|
||||
return res.status(e.status || 500).json(monkeyError);
|
||||
});
|
||||
|
||||
app.listen(PORT, async () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue