diff --git a/.travis.yml b/.travis.yml index 95f0697..4a550b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/lib/pushover.js b/lib/pushover.js index efdfbbe..69b0403 100644 --- a/lib/pushover.js +++ b/lib/pushover.js @@ -134,7 +134,7 @@ Pushover.prototype.errors = function (d, res) { try { d = JSON.parse(d) } catch (error) { - throw new Error('JSON parsing failed', res) + this.onerror(error, res) } } @@ -142,6 +142,7 @@ Pushover.prototype.errors = function (d, res) { 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) } } diff --git a/package.json b/package.json index 4ef5520..243e799 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Aaron Bieber ", "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", diff --git a/test/test-10-onerror.js b/test/test-10-onerror.js new file mode 100644 index 0000000..6a3c479 --- /dev/null +++ b/test/test-10-onerror.js @@ -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') + }); +});