Skip to content

Commit

Permalink
add a fix for pushover returning html
Browse files Browse the repository at this point in the history
  • Loading branch information
qbit committed Jan 30, 2020
1 parent 9118bfc commit 2f2fcb6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_js:
env:
global:
- secure: cji+CqW+TmOqGBGk30ijZRGZ9zwpVCncp6iptnpMXhEqBmGJ1Q15rEWZxAyqbqHeEsPqAlT1FecjuyCnTSVowxLJvfwLKUtsqeXSazNRJey22jee648UfNNxGSUjAL2fCK9AQlTZ0k4Jc0xVqodGNrQbzA2K82BC7oG6wOZDji0=
- secure: DpGUIEnMXXebOq5C2ConWx0KLNEXZ5UiZ2Gd3vPOXOyQuhevJM9c4F9j+6L5novFwNVs2ceksCr/aEt42hCaBqw+5PlpcBM9Ll+zK0PQrxoZPT2jzl0nHLufGtWT7sCYY7xWvR519iEM8pFNpkM9KYeRU9luY/8flP+L6jb34Os=
matrix:
secure: BX0GyzK8qZAFJlpzJ2nLiaAy0e/wYmYhKTpRcMRcsipfoGeQSQ18B1HqC3Vy9SGc0hox8sVwS8KUPwMd0ZqRC0wOc57PioJC5bDmOZ48bQcREITlcO2b8RGaEdDosIXdinJ346LHUPccDGXLp2ZdKqVE4IV+xRA8o86KoTKmhh8=
before_install:
Expand Down
3 changes: 2 additions & 1 deletion lib/pushover.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ Pushover.prototype.errors = function (d, res) {
try {
d = JSON.parse(d)
} catch (error) {
throw new Error('JSON parsing failed', res)
this.onerror(error, res)
}
}

if (d.errors) {
if (this.onerror) {
this.onerror(d.errors[0], res)
} else {
// If no onerror was provided throw our error
throw new Error(d.errors[0], res)
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Aaron Bieber <aaron@qbit.io>",
"name": "pushover-notifications",
"description": "Pushover API for node.js",
"version": "1.2.1",
"version": "1.2.2",
"homepage": "http://github.com/qbit/node-pushover",
"repository": {
"type": "git",
Expand Down
27 changes: 27 additions & 0 deletions test/test-10-onerror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var Push = require('../lib/pushover.js')

var p = new Push({
user: process.env['PUSHOVER_USER'],
token: process.env['PUSHOVER_TOKEN'],
update_sounds: false,
debug: true,
onerror: function (err, res) {
if (res.statusCode == 429) {
process.exit(0)
}
}
})

var msg = {
message: 'test from ' + process.argv[1],
sound: 'magic',
title: 'Well - this is fantastic'
}

var ten = [1,2,3,4,5,6,7,8,9,10];

ten.forEach(function() {
p.send(msg, function (err, result, res) {
console.log('====> On error test')
});
});

0 comments on commit 2f2fcb6

Please sign in to comment.