Skip to content

Commit 9614dd0

Browse files
committed
feat(logging): add error description when logging errors.
1 parent 28030c5 commit 9614dd0

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var _ = require('lodash');
22
var httpProxy = require('http-proxy');
3+
var errno = require('errno');
34
var configFactory = require('./config-factory');
45
var handlers = require('./handlers');
56
var contextMatcher = require('./context-matcher');
@@ -128,9 +129,14 @@ function HttpProxyMiddleware(context, opts) {
128129
}
129130

130131
function logError(err, req, res) {
131-
var hostname = (req.hostname || req.host) || (req.headers && req.headers.host); // (node0.10 || node 4/5) || (websocket)
132-
var targetUri = (proxyOptions.target.host || proxyOptions.target) + req.url;
133-
134-
logger.error('[HPM] PROXY ERROR: %s. %s -> %s', err.code, hostname, targetUri);
132+
var hostname = (req.headers && req.headers.host) || (req.hostname || req.host); // (websocket) || (node0.10 || node 4/5)
133+
var target = proxyOptions.target.host || proxyOptions.target;
134+
var description = errno.code[err.code] && errno.code[err.code].description; // description for the error code
135+
136+
if (description) {
137+
logger.error('[HPM] Error \'%s\' (ErrorCode=%s) occurred while trying to proxy request %s from %s to %s', description, err.code, req.url, hostname, target);
138+
} else {
139+
logger.error('[HPM] Error (ErrorCode=%s) occurred while trying to proxy request %s from %s to %s', err.code, req.url, hostname, target);
140+
}
135141
}
136142
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"http-proxy": "^1.14.0",
5252
"is-glob": "^2.0.1",
5353
"lodash": "^4.14.2",
54-
"micromatch": "^2.3.11"
54+
"micromatch": "^2.3.11",
55+
"errno": "^0.1.4"
5556
}
5657
}

0 commit comments

Comments
 (0)