Skip to content

Commit

Permalink
Handle all HTTP errors correctly (#379)
Browse files Browse the repository at this point in the history
* fix: handle non-http errors correctly (#375)

* fix: handle all HTTP errors correctly (#378)
  • Loading branch information
silentjohnny authored Oct 10, 2023
1 parent cc6fa1a commit a235d24
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ Sender.prototype.sendNoRetry = function(message, recipient, callback) {
.then((res) => {
const { data: resBodyJSON, status } = res;

if (status !== 200) {
debug('Invalid request (' + status + '): ' + resBodyJSON);
return callback(status);
}

if (_.isEmpty(resBodyJSON)) {
debug('Empty response received (' + status + ' ' + res.statusText + ')');
// Spoof error code 400 to avoid retrying the request
Expand All @@ -183,6 +178,12 @@ Sender.prototype.sendNoRetry = function(message, recipient, callback) {
debug('GCM service is unavailable (500)');
return callback(res.status);
}

if (res.status !== 200) {
debug('Invalid request (' + res.status + '): ' + res.data);
return callback(res.status);
}

}

return callback(err);
Expand Down

0 comments on commit a235d24

Please sign in to comment.