parkpow / deep-license-plate-recognition

Automatic License Plate Recognition (ALPR) or Automatic Number Plate Recognition (ANPR) software that works with any camera.
https://platerecognizer.com/
MIT License
523 stars 122 forks source link

feat: improve Verkada Rate Limit Retry #213

Closed danleyb2 closed 1 month ago

danleyb2 commented 1 month ago

obey to a 5 second cooldown period before attempting the Rate Limited requests again

github-actions[bot] commented 1 month ago

Risk Level 2 - /home/runner/work/deep-license-plate-recognition/deep-license-plate-recognition/parkpow/verkada-lpr-webhooks/cf-workers/src/index.js

The fetchWithRetry function has been modified to include a hardcoded delay of 5100ms for rate-limited requests. While this approach can mitigate the issue of hitting the rate limit, it's not adaptive to different rate-limiting policies that the server might enforce. Consider the following improvements:

  1. Adaptive Delay: Instead of a fixed delay, use a response header (e.g., Retry-After) to determine the appropriate wait time if the server provides it.

    const delay = response.headers.get('Retry-After') * 1000 || 5100;
    return wait(delay).then(() => fetchWithRetry(url, init, tries - 1));
  2. Error Logging: The error logging within the catch block of fetchWithRetry logs error.data, which might not be a string. Ensure that the error message is properly formatted to avoid [object Object] in logs.

    console.error(`fetchWithRetry error: ${error.name} - ${error.message}`);
  3. Error Handling: The catch block rethrows the error if it's an instance of Error429 or Error5xx, or if the number of tries is less than 1. This is a good practice, but ensure that the calling code is prepared to handle these exceptions appropriately.


⏲️🔧📜


Powered by Code Review GPT