Skip to content

Commit

Permalink
catch crashes parsin JSON mateodelnorte#17
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Shevchenko committed Apr 26, 2017
1 parent d1a8c86 commit 3f91c5c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ Forecast.prototype.getAtTime = function getAtTime (latitude, longitude, time, op
request.get({uri:url, timeout:this.requestTimeout}, function (err, res, data) {
if (err) {
callback(err);
} else {
data = JSON.parse(data);
} else if(res.headers['content-type'].indexOf('application/json') > -1) {
callback(null, res, JSON.parse(data));
} else if(res.statusCode === 200) {
callback(null, res, data);
} else {
callback(new ForecastError(data), res, data);
}
});
};
Expand Down

0 comments on commit 3f91c5c

Please sign in to comment.