diff --git a/src/server.js b/src/server.js index 7c63a3f..37575c6 100755 --- a/src/server.js +++ b/src/server.js @@ -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