Does not detect errors properly #1

Closed
Jellyfrog opened this Issue Feb 15, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@Jellyfrog
Contributor

Jellyfrog commented Feb 15, 2013

Code

prowl.push(null, 'test', function(err, remaining) {
  if(err) throw err;
  console.log( 'I have ' + remaining + ' calls to the api during current hour. BOOM!' );
});

Error:

/usr/home/node/node/site-ponger/node_modules/node-prowl/lib/prowl.js:75
                        callback( error, result['success']['@']['remaining']*1 );
                                                          ^
TypeError: Cannot read property '@' of undefined
    at push (/usr/home/node/node/site-ponger/node_modules/node-prowl/lib/prowl.js:75:38)
    at Parser.exports.Parser.Parser.parseString (/usr/home/node/node/site-ponger/node_modules/node-prowl/node_modules/xml2js/lib/xml2js.js:134:18)
    at Parser.EventEmitter.emit (events.js:96:17)
    at Object.exports.Parser.Parser.reset.saxParser.onclosetag (/usr/home/node/node/site-ponger/node_modules/node-prowl/node_modules/xml2js/lib/xml2js.js:120:24)
    at emit (/usr/home/node/node/site-ponger/node_modules/node-prowl/node_modules/xml2js/node_modules/sax/lib/sax.js:589:33)
    at emitNode (/usr/home/node/node/site-ponger/node_modules/node-prowl/node_modules/xml2js/node_modules/sax/lib/sax.js:594:3)
    at closeTag (/usr/home/node/node/site-ponger/node_modules/node-prowl/node_modules/xml2js/node_modules/sax/lib/sax.js:834:5)
    at Object.write (/usr/home/node/node/site-ponger/node_modules/node-prowl/node_modules/xml2js/node_modules/sax/lib/sax.js:1253:29)
    at Parser.exports.Parser.Parser.parseString (/usr/home/node/node/site-ponger/node_modules/node-prowl/node_modules/xml2js/lib/xml2js.js:145:29)
    at Parser.__bind [as parseString] (/usr/home/node/node/site-ponger/node_modules/node-prowl/node_modules/xml2js/lib/xml2js.js:3:63)

Output from request

{ error:
   { '#': 'Missing field: Event or description is required.',
     '@': { code: '400' } } }

The logic is a bit weird in the error handler.
First you check if result.success exist or not if( !result['success'] ) error = err;
but you're always trying to access it callback( error, result['success']['@']['remaining']*1 );

@arnklint

This comment has been minimized.

Show comment
Hide comment
@arnklint

arnklint Feb 15, 2013

Owner

SHA: fc03b73 fixes this, thanks for the contributions @Jellyfrog !

Owner

arnklint commented Feb 15, 2013

SHA: fc03b73 fixes this, thanks for the contributions @Jellyfrog !

@arnklint arnklint closed this Feb 15, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment