mixpanel-node icon indicating copy to clipboard operation
mixpanel-node copied to clipboard

Import batch does not handle rate limiting

Open BjornTheProgrammer opened this issue 1 year ago • 0 comments

The following code just console errors a bunch when running.

import Mixpanel from 'mixpanel';

const mixpanel = Mixpanel.init('1185e7d1999cbf30e66076c105b11c49', {
    secret: 'd8bb5e232b89a8b5adc88d500ac78106'
});

const events = [
    {
        event: 'Thing',
        properties: {
            ...
        }
    },
    ...
]

mixpanel.import_batch(events, (errs) => { // Events is very, very large
    console.error(errs);
})
      at /Users/bjorn/Desktop/project/node_modules/mixpanel/lib/mixpanel-node.js:147:42
      at endReadableNT (node:stream:2426:53)
, 142 |                     catch(ex) {
143 |                         e = new Error("Could not parse response from Mixpanel");
144 |                     }
145 |                 }
146 |                 else {
147 |                     e = (data !== '1') ? new Error("Mixpanel Server Error: " + data) : undefined;
                                               ^
error: Mixpanel Server Error: {"error":"Project exceeded rate limits. Please retry the request with exponential backoff.","status":0}

Seems to me that the library should handle the issue of rate limiting, instead of the end user. Discord.js is an example of this. It's library handles potential rate limiting issues. Please consider adding this as a feature.

BjornTheProgrammer avatar Mar 22 '24 00:03 BjornTheProgrammer