blakejoy / tmdb-ts

Typescript client wrapper for TheMovieDB (TMDB) v3
MIT License
37 stars 12 forks source link

Feature Request: Retries when rate limited #38

Open benlei opened 10 months ago

benlei commented 10 months ago

Is your feature request related to a problem? Please describe. It would be nice if there was a built in retry mechanism, specifically for when TMDB responds back with a rate limit error (https://developer.themoviedb.org/docs/rate-limiting)

I plan to build something that would potentially have multiple nodes/workers that call TMDB's API, and it'd be great if when I hit the rate limit, intentionally or not, that the library waits the suggested wait time provided by TMDB.

Describe the solution you'd like

Add a flag to enable retry, where when TMDB returns a 429 response, retry the request based on the response's Retry-After header.

Describe alternatives you've considered

I've considered just adding in a manual retry if this library throws an exception, but it'd be nice if I pass along a retry enabled flag so that the library can deal with retries for me.

Additional context

A Golang version of the TMDB library seems to do this: https://github.com/cyruzin/golang-tmdb/blob/550e16359e0dc11bee79cdda30c470f7b96081a2/tmdb.go#L189

A JS version seems to have also implemented this: https://github.com/gajus/tmdb/blob/master/src/Tmdb.js#L49

Edit: I'm honestly not sure if either strategies work... I can tell that TMDB is using CloudFront, but to be honest I'm not sure how to tell when CloudFront rate limits or if they return any headers on when they can retry.

blakejoy commented 5 months ago

Hmm is this still something you want to see @benlei ?

benlei commented 3 months ago

@blakejoy Yep would be nice if this was built in