mirror of
https://github.com/detleph/server.git
synced 2026-09-06 07:56:19 +02:00
Add basic error handling
+ Add express-async-errors package to handle async errors + Add ForwaradableError class (Base class for all project-specific errors) + Add defaultErrorHandler middleware which handles errors and sends info to the client
This commit is contained in:
@@ -6,6 +6,10 @@ import argon2 from "argon2";
|
||||
import adminRouter from "./Routes/admin.routes";
|
||||
import organisationRouter from "./Routes/organisation.routes";
|
||||
import groupRouter from "./Routes/group.routes";
|
||||
import defaultErrorHandler from "./Middleware/error/handler";
|
||||
|
||||
// Set up async error handling
|
||||
require("express-async-errors");
|
||||
|
||||
require("dotenv").config(); // Load dotenv config
|
||||
|
||||
@@ -52,6 +56,9 @@ async function main() {
|
||||
|
||||
app.use("/api/groups", groupRouter);
|
||||
|
||||
// Error handling
|
||||
app.use(defaultErrorHandler);
|
||||
|
||||
app.listen(process.env.PORT, () => {
|
||||
console.log(`Listening on Port: ${process.env.PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user