From 9f2352443b951a573656016bf84e0b4b1fda13e8 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Wed, 2 Sep 2015 10:08:16 -0700 Subject: [PATCH] Add error handling for missing elasticsearch index. Closes #7 --- series_functions/es.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/series_functions/es.js b/series_functions/es.js index 6f12bc3c368579..fe9e1087bbc686 100644 --- a/series_functions/es.js +++ b/series_functions/es.js @@ -159,6 +159,8 @@ module.exports = new Datasource('es', { var body = buildRequest(config, tlConfig); return client.search(body).then(function (resp) { + if (!resp._shards.total) throw new Error('Elasticsearch index not found: ' + config.index); + var data = _.map(resp.aggregations.series.buckets, function (bucket) { var value; if (resp.aggregations.series.buckets[0].metric != null) {