yahoo-fantasy-sports-api: Unable to catch error encountered when blocked by Yahoo for making too many requests
Hey Luke,
When making too many requests to Yahoo, Yahoo blocks us for a short period of time based on the app ID we have registered on their developer portal.
I am looking to catch this error so that I can handle it properly and send an informative error message to the front end of the application. However I cannot catch the error using try catch or .then.catch syntax, and when the error occurs the program crashes. The error is occuring in YahooFantasy.mjs and occurs when parsing the result from Yahoo.

The issue seems to be occurring when trying to use JSON.parse to parse the “Request denied” response from Yahoo (possibly line 287 in YahooFantasy.mjs?) but I am not sure why this error is uncatchable.
Here are some examples of how I am trying to handle the error:
yf.players.leagues(sandlot, { start: 0 }, ['stats', 'ownership', 'percent_owned', 'draft_analysis']).then((result) => { console.log(result) }).catch((error) => { console.log(error) // Never reached })
try { const result = yf.players.leagues(sandlot, { start: 0 }, ['stats', 'ownership', 'percent_owned', 'draft_analysis']) } catch (e) { console.log(e) // Never reached }
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 30 (9 by maintainers)
@ptoninato Here are my notes from a while ago very roughly determining the rate limit. Its very rough because I was making 120 calls at a time and did this twice, with failure happening on the second batch of calls. You could test this more exactly by making individual calls until you hit the limit and recording how many calls you made.
I did some tests and determined the API is blocked at an app registration level (you are identified and blocked based on the API keys you get from Yahoo after registering the app, rather than specific user’s being blocked based on their access or refresh token)
To get around this you could register multiple times to get extra sets of credentials, and switch between the credentials whenever you are blocked. This is against Yahoo ToS however.
I did some fun tests with the API to discover how the rate limiting. This is nothing conclusive but should give us a hint…
Sending requests back to back like in my script below:
Will trip the rate limiting at or before 500 requests.
If I add the one second delay, it trips the rate limiting at just over 1000 requests (but that’s after waiting for almost twenty minutes 😢 )
Once you are rate limited, you are blocked for 5 minutes, however this number seems to increase or will just totally block you if you keep tripping the rate limit (or it could be the number just increases a lot that you might as well just get a new token)
Another fun note, if you send the requests after your 5 minute block is over, the amount of requests you can receive decreases – on my experiment I got the following results:
It appears to be that after the 5 minute block, you get 35% less requests? 325/500 = 0.65, which turns out to be a 35% difference. 325 * .35 is 114 rounded up, which is really close to the third run result: 325 - 114 = 211. The 3rd run was ran just a few seconds after 5 minute was up, suggesting that after that fact, a timer is ran to slowly increase your requests limit back.
This is perhaps backup by my 4th run, I ran it after it was closer to ten minutes instead of 5. When I ran that request, I got rate limited at 318 requests. So whatever the case it’s definitely some backoff formula that they are using that will “give you requests” back after seconds/minutes go by.
Either the case this was just a small test I ran, nothing concrete on how exactly it works but these were my finds non the less 😃
@HappyZombies - from my own experience, where we connect users to Yahoo via OAuth, I mostly see the rate limit is applied on a per-user basis, not per-app.
I had a similar experience: during development, hit rate limits because I was doing a lot of refreshes and probably should have been caching.
But my app connects a huge number of Yahoo users essentially simultaneously, and we do see some rate limits hit, but I think that’s individual user behavior, and not applied across our entire registered application.
I agree it’s a bummer the rate limits are opaque. I understand Yahoo’s position here, but it’s pretty unhelpful, especially since they’re so difficult to get in touch with to coordinate raised limits (we still have yet to get a good contact).
Still, if you do the right caching and make efficient queries, your users should mostly be fine.
Probably a couple seconds, I would make a request and as soon as I received the result make the next request. There may be different limits for situations when you are making calls over a greater interval of time
On Mon., Jul. 18, 2022, 12:21 p.m. Tyler Scott Williams, < @.***> wrote:
Thanks, I’ll check this out.
In the meantime, I got a response yesterday!
“As far as rate limits, nothing published about it; we are kind of loose about app-based rate limits and instead enforce some general abuse-oriented rate limits. It’s on the order of a couple thousand requests per hour, but don’t have it handy now.”
So if that’s something different than what you’re seeing we could be running into a different issue…
It sounds ominous when you call it “The Machine”!
I will give it a test later tonight and get back to you. Hope your connect comes back from AWOL soon