mixpanel / mixpanel-node

A node.js API for mixpanel
http://www.mixpanel.com
MIT License
477 stars 159 forks source link

Import batch does not handle rate limiting #231

Open BjornTheProgrammer opened 8 months ago

BjornTheProgrammer commented 8 months ago

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.