Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trap errors from the export endpoint #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michaelcarter
Copy link
Owner

@michaelcarter michaelcarter commented Nov 1, 2018

Mixpanel's non-export API endpoints give 200 status codes with a JSON error when something goes wrong, but the export endpoint gives a non-200 status code with a string. The library was trying to parse this into JSON, failing awkwardly and blowing up.

This isn't really a full fix, as ideally we'd have promises rejecting properly with errors when they occur, but it should at least make the export API's behaviour consistent with behaviour of the other methods and give a similarly structured { error: "foobar" } object

@GeoffreyPlitt
Copy link

@michaelcarter

Is this working? I switched to this branch and still get untrapped errors.

Or if this is working, are you going to merge it?

@GeoffreyPlitt
Copy link

Here's what my error logs look like:
undefined:1 [terminated early] ^ SyntaxError: Unexpected token e in JSON at position 2 at Object.parse (native) at MixpanelExport._parseResponse (/app/node_modules/mixpanel-data-export/src/mixpanel_data_export.js:180:17) 21) 25) at setState (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:614:14) at IncomingMessage.<anonymous> (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13) 20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickDomainCallback (internal/process/next_tick.js:128:9)

@michaelcarter
Copy link
Owner Author

@GeoffreyPlitt I'll need to put aside some time to look back into this for you.

I'm not saying it's the case here, but historically I've had issues with Mixpanel not consistently returning valid JSON (or even consistent error messages), their export API is prone to breaking changes.

Could you give me some info on the request you're making so I can recreate this locally please? I can then either put in a fix, or add some pointers on here for someone else to put in a PR.

@GeoffreyPlitt
Copy link

Gotcha. We're doing mixpanel_exporter.export() with an opts object like this:

{
        event: ['ev1', 'ev2', 'ev3'],
        from_date: '2019-03-01',
        to_date: '2019-03-05',
        where: `"44845" in properties["field1"]`
      }

@GeoffreyPlitt
Copy link

Another one

Mar 05 13:12:41 stardust-backend app/trailer_insights_prefetch.1: Received 2122 raw datapoints from Mixpanel. Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: undefined:1 Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: [{"event":"impression","properties":{"time":1543155025,"distinct_id":"c92efae6-b148-45ee-8e42-f2cdabd275b4","$city":"Ashburn","$region":"Virginia","cameFrom":"home_daily_row","dob":"1997-05-04T21:00:00","gender":"MALE","mediaId":524247,"mediaType":"movie","mp_country_code":"US","mp_lib":"node","mp_processing_time_ms":1543183825874,"trailerId":"f25b9757-2b32-45f7-8e26-e032d1316762","username":"JPartin"}},{"event":"impression","properties":{"time":1543155034,"distinct_id":"c6568763-4666-45f9-8bd5-fbf08a660f71","$city":"Ashburn","$region":"Virginia","cameFrom":"home_daily_row","dob":"1978-11-19T21:00:00","gender":"MALE","mediaId":524247,"mediaType":"movie","mp_country_code":"US","mp_lib":"node","mp_processing_time_ms":1543183835074,"trailerId":"f25b9757-2b32-45f7-8e26-e032d1316762","username":"kenw420"}},{"event":"impression","properties":{"time":1543155038,"distinct_id":"b37000b5-8762-4c0b-90fc-dddb5b2c3949","$city":"Hillsboro","$region":"Oregon","cameFrom":"home_daily_row","dob":"1997-09-16T00:00 Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: SyntaxError: Unexpected token ] in JSON at position 15135 Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at Object.parse (native) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at MixpanelExport._parseResponse (/app/node_modules/mixpanel-data-export/src/mixpanel_data_export.js:180:17) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at request.onload (/app/node_modules/mixpanel-data-export/src/mixpanel_data_export.js:151:21) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at dispatchEvent (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at setState (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:614:14) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at IncomingMessage.<anonymous> (/app/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at emitNone (events.js:91:20) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at IncomingMessage.emit (events.js:185:7) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at endReadableNT (_stream_readable.js:974:12) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at _combinedTickCallback (internal/process/next_tick.js:80:11) Mar 05 13:16:00 stardust-backend app/trailer_insights_prefetch.1: at process._tickDomainCallback (internal/process/next_tick.js:128:9) Mar 05 13:16:03 stardust-backend app/trailer_insights_prefetch.1: trailer_insights_prefetching: Starting...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants