Skip to content

Commit 65f63f5

Browse files
committed
added the error handling to avoid http-party/node-http-proxy#527
1 parent 8b05eb0 commit 65f63f5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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)