diff --git a/src/routes/graphs.js b/src/routes/graphs.js index 084b591be..187ede538 100644 --- a/src/routes/graphs.js +++ b/src/routes/graphs.js @@ -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)); + }); }