Skip to content

Commit

Permalink
apply better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
metagrover committed Jun 5, 2018
1 parent 8ac211a commit cdb3173
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/fetch_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ var fetchRequest = function () {
}

(0, _crossFetch2.default)(this.client.protocol + "://" + this.client.url + "/" + this.client.appname + "/" + this.path + "?" + _querystring2.default.stringify(this.params), requestOptions).then(function (res) {
if (res.status >= 500) {
_this.resultStream.emit("error", res);
return;
}

res.json().then(function (data) {
if (res.status >= 400) {
_this.resultStream.emit("error", res);
Expand Down
5 changes: 5 additions & 0 deletions src/fetch_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export default class fetchRequest {

fetch(`${this.client.protocol}://${this.client.url}/${this.client.appname}/${this.path}?${querystring.stringify(this.params)}`, requestOptions)
.then(res => {
if (res.status >= 500) {
this.resultStream.emit("error", res);
return;
}

res.json().then(data => {
if (res.status >= 400) {
this.resultStream.emit("error", res);
Expand Down
4 changes: 2 additions & 2 deletions test/msearch_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ searchTests.searchForDocs = function searchForDocs(streamingClient, done) {
})
.on("error", function(e) {
console.log(e);
done();
done(e);
})
.on("data", function(res) {
// index second tweet
Expand All @@ -21,7 +21,7 @@ searchTests.searchForDocs = function searchForDocs(streamingClient, done) {
})
.on("error", function(e) {
console.log(e);
done();
done(e);
})
.on("data", function(res) {
var first = true;
Expand Down

0 comments on commit cdb3173

Please sign in to comment.