Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Liam-OShea opened this issue Nov 2, 2020 · 1 comment

Comments

@Liam-OShea
Copy link

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: ''
}
@whatadewitt
Copy link
Owner

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.

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

No branches or pull requests

2 participants