ActiveCampaign / activecampaign-api-nodejs

Node.js wrapper for the ActiveCampaign API
MIT License
39 stars 36 forks source link

Unable to parse errors #21

Closed eahenke closed 8 years ago

eahenke commented 8 years ago

Lately when I've been trying to query Active Campaign's api, it has been returning what looks like an out of service message:

<div align="center" style="font-size:12px; font-family:Arial;">We are currently having some issues. Please check back soon.</div>

However, it looks like the node wrapper attempts to JSON.parse() this response, and this causes the script to crash.

Here is the relevant stack trace:

<div align="center" style="font-size:12px; font-family:Arial;">We are currently having some issues.  Please check back soon.</div>
^

SyntaxError: Unexpected token <
    at Object.parse (native)
    at Request._callback (/Users/eahenke/github/integrator/node_modules/activecampaign/lib/Connector.js:190:35)
    at Request.self.callback (/Users/eahenke/github/integrator/node_modules/activecampaign/node_modules/request/request.js:200:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/Users/eahenke/github/integrator/node_modules/activecampaign/node_modules/request/request.js:1067:10)
    at emitOne (events.js:82:20)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/Users/eahenke/github/integrator/node_modules/activecampaign/node_modules/request/request.js:988:12)
    at Object.forward (/usr/local/lib/node_modules/strongloop/node_modules/strong-agent/lib/proxy.js:79:23)
    at IncomingMessage.eval (eval at wrap (/usr/local/lib/node_modules/strongloop/node_modules/strong-agent/lib/proxy.js:201:20), <anonymous>:3:21)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at /Users/eahenke/github/integrator/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31
    at nextTickCallbackWith2Args (node.js:441:9)
    at process._tickDomainCallback (node.js:396:17)
    at process.fallback (/Users/eahenke/github/integrator/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/index.js:450:15)```
eahenke commented 8 years ago

Also it appears using npm install activecampaign pulls down an outdated version of the module, which lacks the most recent two commits 17437e507c705ea8b43930bac512a39f85120788 and 713a8a317d4ed621257ace2f9a9aa49d99af92d9. It looks like former of those commits was aimed at this issue by adding a try/catch block for the JSON.parse. However, this does not fix the problem. After rejecting the promise when the parse fails, the code outside the block runs and it tries to parse again, this time failing at line 154.

molinto commented 8 years ago

Same issue. NPM is now on v1.2.1 :)

pevans commented 8 years ago

@molinto is correct; we are now on version 1.2.1, and that should fix this issue for you going forward.