Handle error in graphs code

This commit is contained in:
Girish Ramakrishnan
2019-09-05 12:01:25 -07:00
parent bd1fbc4a05
commit 147f16571a
+10 -1
View File
@@ -5,6 +5,7 @@ exports = module.exports = {
};
var middleware = require('../middleware/index.js'),
HttpError = require('connect-lastmile').HttpError,
url = require('url');
// for testing locally: curl 'http://127.0.0.1:8417/graphite-web/render?format=json&from=-1min&target=absolute(collectd.localhost.du-docker.capacity-usage)'
@@ -24,6 +25,14 @@ function getGraphs(req, res, next) {
// nginx still has a request timeout which can deal with this then.
req.clearTimeout();
graphiteProxy(req, res, next);
graphiteProxy(req, res, function (error) {
if (!error) return next();
if (error.code === 'ECONNREFUSED') return next(new HttpError(424, 'Unable to connect to graphite'));
// ECONNRESET here is most likely because of a bug in the query or the uwsgi buffer size is too small
if (error.code === 'ECONNRESET') return next(new HttpError(424, 'Unable to query graphite'));
next(new HttpError(500, error));
});
}