Permalink
Browse files

Better error handling and reporting. The callback is now passed an ap…

…proapriate error object based on the return value from ES.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent e287bf4 commit 222cd812fdc34cdad1984756728cc63838228231 @ncb000gt committed Mar 3, 2011
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/elasticsearch.js
View
@@ -109,9 +109,13 @@ ElasticSearch.prototype._request = function(opts, data, cb) {
chunk.copy(buf, total, 0);
total += buf.length;
});
-
+ var res_json = JSON.parse(buf.toString());
if (cb) {
- cb(null, JSON.parse(buf.toString()));
+ if (res_json.status !== 200) {
+ cb(res_json);
+ } else {
+ cb(undefined, res_json);
+ }
}
});
});

0 comments on commit 222cd81

Please sign in to comment.