adding global error handlers

This commit is contained in:
talksik
2022-06-08 05:28:38 -05:00
parent d189f82a60
commit 7aab1ee26c
3 changed files with 13 additions and 6 deletions
+11 -4
View File
@@ -16,10 +16,20 @@ app.use(morgan('combined'));
app.use(cors());
app.use(express.json());
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
console.error(err);
next(err);
});
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
res.status(500);
res.render('error', { error: err });
});
app.get('/', (req: Request, res: Response) => {
res.send('hello world.');
});
app.use('/api/status', (req: Request, res: Response) => {
app.get('/api/status', (req: Request, res: Response) => {
res.json({ message: 'wohoo, server is healthy' });
});
@@ -28,9 +38,6 @@ const server = app.listen(PORT, () =>
console.log(`express running on port | ${PORT} in host machine`),
);
// won't catch any errors here and we don't want it to
console.log();
const io = require('socket.io')(server, {
// todo: add authentication
cors: {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"ignore": ["**/*.test.ts", "**/*.spec.ts", "node_modules"],
"watch": ["./", "../common"],
"watch": ["./", "../core"],
"exec": "npm run start:dev",
"ext": "ts"
}
+1 -1
View File
@@ -5,7 +5,7 @@
"license": "MIT",
"scripts": {
"core": "rm -rf ./core && cp -r ../core/src ./core/",
"dev": "NODE_ENV=development && yarn core && nodemon",
"dev": "NODE_ENV=development nodemon",
"start:dev": "ts-node index.ts",
"lint": "eslint --ext .ts,.tsx .",
"build": "npm run lint && tsc -p .",