Skip to content

Commit ac1b268

Browse files
authored
Merge pull request #66 from eldimious/feature/use-express-error-handler
start using express-error-handler
2 parents 0eeae1f + c79580d commit ac1b268

File tree

5 files changed

+68
-71
lines changed

5 files changed

+68
-71
lines changed

package-lock.json

Lines changed: 63 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"homepage": "https://github.com/eldimious/nodejs-api-showcase#readme",
2323
"dependencies": {
2424
"@dimosbotsaris/express-async-handler": "^1.0.2",
25+
"@dimosbotsaris/express-error-handler": "^1.0.2",
2526
"@hapi/joi": "^17.1.1",
2627
"bcryptjs": "^2.4.3",
2728
"body-parser": "^1.19.1",

src/presentation/http/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const helmet = require('helmet');
88
const path = require('path');
99
const swaggerUi = require('swagger-ui-express');
1010
const asyncWrapper = require('@dimosbotsaris/express-async-handler');
11+
const { errorHandler } = require('@dimosbotsaris/express-error-handler');
1112
const authenticateEndpoint = require('./middleware/authentication');
1213
const authRoutes = require('./routes/auth/routes');
1314
const usersRoutes = require('./routes/users/routes');
14-
const errorRoute = require('./routes/errors');
1515
const swaggerDocument = require('../../swagger');
1616

1717
const app = express();
@@ -34,8 +34,7 @@ module.exports.init = (services) => {
3434
next();
3535
});
3636
app.use('/users', usersRoutes.init(services));
37-
app.use(errorRoute);
38-
37+
app.use(errorHandler({ trace: true }));
3938
const httpServer = http.createServer(app);
4039
return httpServer;
4140
};

src/presentation/http/middleware/endpointValidator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {
55
param,
66
validationResult,
77
} = require('express-validator');
8-
const errorHandler = require('../routes/errors');
8+
const { errorHandler } = require('@dimosbotsaris/express-error-handler');
99
const errors = require('../../../common/errors');
1010
const {
1111
PASSWORD_COMPLEXITY,
@@ -141,7 +141,7 @@ const validate = (req, res, next) => {
141141
})[0];
142142
const errMsg = validationError?.msg?.message || 'Bad request';
143143
const errStatus = validationError?.msg?.status || 400;
144-
return errorHandler(new errors[errStatus](errMsg, 'BAD_BODY_PARAMS'), req, res, next);
144+
return errorHandler({ trace: true })(new errors[errStatus](errMsg, 'BAD_BODY_PARAMS'), req, res, next);
145145
};
146146

147147
const validateCreateUserBody = () => [

src/presentation/http/routes/errors/index.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)