whatadewitt / yahoo-fantasy-sports-api

NodeJS wrapper for the Yahoo! Fantasy Sports API
https://yahoo-fantasy-node-docs.vercel.app/
MIT License
192 stars 52 forks source link

Way to retry request after refreshing token with new 4.0.0 token refresh feature? #64

Open Liam-OShea opened 3 years ago

Liam-OShea commented 3 years ago

Sorry for all the issues! I am enjoying using your app.

I noticed when playing with the new token refresh feature in 4.0.0 that when the token is expired, a new token is requested from Yahoo and supplied to the callback function, but the original request to the API is not remade with the new token.

Is there a way configure it so that the original request is remade upon a successful refresh of the access token?

whatadewitt commented 3 years ago

Hey @LudicrousLiam, sorry I'm not getting any emails from Github.

I had this built in and then removed it because of issues where users might not specify some of the stuff needed...

If you look at the old fantasy sandbox / docs source code that I had before I built the new version using Next, I have this workflow outlined here: https://github.com/whatadewitt/yahoofantasysandbox/blob/master/routes/index.js#L63

This is a bit convoluted as this lives inside of a catchall route so it can execute any request -- but I think it's what you're looking for.

Basically, I'm using a callback function and you can see on line 70 that if it errors I am refreshing the token and then re-submitting the request. This same workflow MIGHT actually live somewhere in the history of the new sandbox / docs site https://github.com/whatadewitt/fantasy-docs-next/blob/master/pages/api/yahoo/%5B%5B...slug%5D%5D.js as well, but I don't have time to search through it right now.

Again, sorry for the delayed response! Hope I am not too late!