Skip to content

Commit 9878742

Browse files
committed
Merge pull request #144 from leonli/patch-for-http-proxy
Added the error handling to avoid http-party/node-http-proxy#527
2 parents fef7f4e + 49ac9ef commit 9878742

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function (config) {
88
singleRun: true,
99

1010
frameworks: [ 'mocha' ],
11-
11+
1212
files: [
1313
'tests.webpack.js'
1414
],

src/server.js

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ app.use('/api', (req, res) => {
2929
proxy.web(req, res);
3030
});
3131

32+
// added the error handling to avoid https://github.com/nodejitsu/node-http-proxy/issues/527
33+
proxy.on('error', (error, req, res) => {
34+
let json;
35+
console.log('proxy error', error);
36+
if (!res.headersSent) {
37+
res.writeHead(500, {'content-type': 'application/json'});
38+
}
39+
40+
json = { error: 'proxy_error', reason: error.message };
41+
res.end(JSON.stringify(json));
42+
});
43+
3244
app.use((req, res) => {
3345
if (__DEVELOPMENT__) {
3446
// Do not cache webpack stats: the script file would change since

0 commit comments

Comments
 (0)