Skip to content

Commit

Permalink
added the error handling to avoid http-party/node-http-proxy#527
Browse files Browse the repository at this point in the history
  • Loading branch information
topsmart20 committed Aug 27, 2015
1 parent b17b972 commit fd2b505
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ app.use('/api', (req, res) => {
proxy.web(req, res);
});

// added the error handling to avoid https://github.com/nodejitsu/node-http-proxy/issues/527
proxy.on('error', (error, req, res) => {
let json;
console.log('proxy error', error);
if (!res.headersSent) {
res.writeHead(500, {'content-type': 'application/json'});
}

json = { error: 'proxy_error', reason: error.message };
res.end(JSON.stringify(json));
});

app.use((req, res) => {
if (__DEVELOPMENT__) {
// Do not cache webpack stats: the script file would change since
Expand Down

0 comments on commit fd2b505

Please sign in to comment.