michaelcarter / mixpanel-data-export-js

Mixpanel data export js
91 stars 38 forks source link

Trap JSON parse errors properly #32

Open GeoffreyPlitt opened 5 years ago

GeoffreyPlitt commented 5 years ago

JSON parsing sometimes fails due to malformed input, and the promise is corrupted (stack dump to console log)

Instead, should capture this in promise-reject for proper promise chain handling.

Example:

SyntaxError: Unexpected token e in JSON at position 2
    at JSON.parse (<anonymous>)
    at MixpanelExport._parseResponse (/app/node_modules/mixpanel-data-export/src/mixpanel_data_export.js:180:17)
    at exports.XMLHttpRequest.request.onload (/app/node_modules/mixpanel-data-export/src/mixpanel_data_export.js:151:21)
    at exports.XMLHttpRequest.dispatchEvent (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
    at setState (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:614:14)
    at IncomingMessage.<anonymous> (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
    at IncomingMessage.emit (events.js:194:15)
    at IncomingMessage.EventEmitter.emit (domain.js:441:20)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)