Skip to content

Commit 004ca9b

Browse files
author
Cristoph Adam Sugianto
committed
adding and showing to console if request error
1 parent 44f0481 commit 004ca9b

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ The list above is based on the client error list and server error list as on thi
161161
- Not Found Route Handler for Express
162162
* version 1.1.0
163163
- Create middleware function to handling 'UnhandledRejection' for asynchronous route in Express
164+
* version 1.2.0
165+
- Adding logging middleware in every request with winston
166+
* version 1.2.1
167+
- Adding and showing error logger to console if request error
168+
164169

165170
# Contributor
166171
* Cristoph Adam Sugianto [@brothergiez][@brothergiez]

lib/handlers/createHandler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { codes, statusCodes } = require('../../lib/constants');
2-
const winston = require('winston');
2+
const { errorLogger } = require('../logger');
33
/**
44
* create handler function
55
* @param {function} handler logic handler to be executed
@@ -13,6 +13,7 @@ const createHandler = (handler) => {
1313
} catch (err) {
1414
error = err;
1515
if (!err.statusCode) {
16+
errorLogger(err, req, res);
1617
return res.status(statusCodes.INTERNAL_SERVER_ERROR).send({
1718
code: statusCodes.INTERNAL_SERVER_ERROR,
1819
statusCode: codes.INTERNAL_SERVER_ERROR,

lib/handlers/errorHandler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { errorLogger } = require('../logger')
1111
*/
1212
const errorHandler = (err, req, res, next) => {
1313
if (err.isCustomError) {
14+
errorLogger(err, req, res);
1415
res.status(err.statusCode).send({
1516
..._.pick(err, ['statusCode', 'code', 'message'])
1617
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "custom-error-exceptions",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Custom error exceptions for microservices",
55
"keywords": [
66
"error",

test/lib/handlers/createHandler.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ describe('createHandler', () => {
1616
res = {
1717
status: () => {
1818
return { send: sinon.stub() };
19-
}
19+
},
20+
on: sinon.stub()
2021
};
2122
next = sinon.stub().returns();
2223
func = createHandler(stub);

0 commit comments

Comments
 (0)