Skip to content

Add rate limit handling to NextDNS API script#3

Open
Minifab wants to merge 1 commit intoHotCakeX:mainfrom
Minifab:nextdns-rate-limit-fix
Open

Add rate limit handling to NextDNS API script#3
Minifab wants to merge 1 commit intoHotCakeX:mainfrom
Minifab:nextdns-rate-limit-fix

Conversation

@Minifab
Copy link

@Minifab Minifab commented May 2, 2025

Add rate limit handling to NextDNS API script

First, I'd like to thank you, HotCakeX, for creating and maintaining this excellent repository. Your work on collecting and organizing Microsoft domains is incredibly valuable for me, and I'm grateful for your contribution to making whitelisting easier for everyone.

I've enhanced the "Add Domains to the NextDNS AllowList.ps1" script to handle NextDNS API rate limits with the following improvements:

  • Implemented an exponential backoff mechanism when encountering "rateLimit" errors
  • Removed retry attempt limits to ensure all domains are eventually added
  • Added small delays between successful requests to reduce the chance of hitting rate limits
  • Integrated PowerShell's native Write-Progress for visual progress tracking
  • Improved status messages and error handling with clear color coding

Why this improvement matters

The current script fails when it encounters rate limit errors after adding multiple domains. With these enhancements, the script will continue trying with progressively increasing intervals (2, 4, 8, 16, 32 seconds...) until the API accepts the request.

These modifications allow the script to work reliably even with a large number of domains to add, intelligently adapting to NextDNS API limitations.

Technical details

  • Used try/catch blocks to properly handle API errors
  • Implemented exponential backoff pattern for rate limit handling
  • Added visual progress bar to track overall completion
  • Maintained all original functionality while adding resilience

This enhancement ensures that users can reliably add all Microsoft domains to their NextDNS allowlist without manual intervention, even when working with the API's rate limits.

@Minifab Minifab requested a review from HotCakeX as a code owner May 2, 2025 00:38
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.

1 participant