From 49fb09956c2bb7cad873c6ce5a361e0449682c34 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 10 Mar 2014 12:17:36 +0800 Subject: [PATCH] Fixed #13, eventually crash when elasticsearch connection error --- lib/es-proxy.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/es-proxy.js b/lib/es-proxy.js index db54cf9..75bf552 100644 --- a/lib/es-proxy.js +++ b/lib/es-proxy.js @@ -37,6 +37,11 @@ function proxyRequest(request, response, host, port, user, password, getProxiedR var proxyReq = http.request(options); + proxyReq.addListener('error', function(err){ + response.status(500).send('Unable to process your request, ' + err.code); + console.log('ElasticSearch Server Error: ' + err.code); + }); + proxyReq.addListener('response', function(proxyResp) { var http10 = request.httpVersionMajor === 1 && request.httpVersionMinor < 1; if(http10 && proxyResp.headers['transfer-encoding'] !== undefined){