yahoo-fantasy-sports-api icon indicating copy to clipboard operation
yahoo-fantasy-sports-api copied to clipboard

UnhandledPromiseRejectionWarning when making request with expired token and no callback/refresh supplied

Open Liam-OShea opened this issue 3 years ago • 1 comments

Hey,

I noticed that as of version 4.0.0 I no longer receive an error message alerting that the access token has expired when a request is made with an expired access token (not using the newly implemented token refresh functionality).

Instead I receive two UnhandledPromiseRejectionWarnings: My Code:

var YahooFantasy = require('yahoo-fantasy');
var yf = new YahooFantasy(
  clientKey,
  clientSecret,
);
yf.setUserToken(
  accessToken
);

// Game
games = async () => {
  try{
    const data = await yf.user.games()
    console.log(data)
  } catch (err){
    console.log(err)
  }
}
games();

The error

(base) PS C:\Users\Liam\Desktop\Work\YahooAPI> node .\accessYahooAPI.js
TypeError: Cannot read property 'users' of undefined
    at C:\Users\Liam\Desktop\Work\YahooAPI\node_modules\yahoo-fantasy\resources\userResource.mjs:19:43
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async games (C:\Users\Liam\Desktop\Work\YahooAPI\accessYahooAPI.js:69:18)
(node:8892) UnhandledPromiseRejectionWarning: #<Object>
(node:8892) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8892) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(base) PS C:\Users\Liam\Desktop\Work\YahooAPI>

I have run the following code to get more info:

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
  // application specific logging, throwing an error, or other logic here
});

And receive this:

(base) PS C:\Users\Liam\Desktop\Work\YahooAPI> node .\accessYahooAPI.js
TypeError: Cannot read property 'users' of undefined
    at C:\Users\Liam\Desktop\Work\YahooAPI\node_modules\yahoo-fantasy\resources\userResource.mjs:19:43
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async games (C:\Users\Liam\Desktop\Work\YahooAPI\accessYahooAPI.js:69:18)
Unhandled Rejection at: Promise Promise {
  <rejected> {
    'xml:lang': 'en-us',
    'yahoo:uri': '/fantasy/v2/users;use_login=1/games?format=json&amp;oauth_consumer_key=***REDACTED***&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1604325103&amp;oauth_nonce=***REDACTED***&amp;oauth_version=1.0&amp;oauth_signature=***REDACTED***',
    description: 'Unauthorized access.',
    detail: ''
  }
} reason: {
  'xml:lang': 'en-us',
  'yahoo:uri': '/fantasy/v2/users;use_login=1/games?format=json&amp;oauth_consumer_key=***REDACTED***&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1604325103&amp;oauth_nonce=***REDACTED***&amp;oauth_version=1.0&amp;oauth_signature=***REDACTED***',
  description: 'Unauthorized access.',
  detail: ''
}

Liam-OShea avatar Nov 02 '20 13:11 Liam-OShea

Hey @LudicrousLiam, catching up on all the issues while I'm here...

Can you verify this is still happening with 4.1.2? I'm happy to fix this but the hour wait while my token expires is a bit of a pain... I'll try to take a look tonight, but if you could confirm that would be great.

whatadewitt avatar Jan 13 '21 13:01 whatadewitt