This commit is contained in:
2022-04-14 20:55:52 +03:00
commit 21d6749497
6 changed files with 169 additions and 0 deletions

24
src/main.ts Normal file
View File

@@ -0,0 +1,24 @@
import express from 'express';
import { config } from 'dotenv';
import { errorHandle } from './utils/error-handling';
config();
const app = express();
const port = process.env.PORT;
app.get('/', (req, res) => {
res.send('hello')
})
app.get('/error', (req, res) => {
throw new Error('some mistake')
})
app.use(errorHandle);
app.listen(port, () => {
console.log(`listen on http://localhost:${port}`);
});

View File

@@ -0,0 +1,5 @@
export const errorHandle = (error, req, res, next) => {
res.status(500).send({
error: error.message || 'some error'
});
};