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

Promise Rejection in fallback #100

Closed
yharish991 opened this issue Sep 30, 2017 · 3 comments
Closed

Promise Rejection in fallback #100

yharish991 opened this issue Sep 30, 2017 · 3 comments
Assignees

Comments

@yharish991
Copy link

yharish991 commented Sep 30, 2017

Can i do something like this ?

function getCache(req, res) {
  return getCacheCB.fire(req.params.userId, req.headers.referer)
    .then(resObj => res.status(resObj.statusCode).send(
        userProfileSerializer(resObj.message, '1.0.0')))
    .catch(resObj => res.status(resObj.statusCode).send(errorSerializer(resObj, '1.0.0')));
}

getCacheCB.fallback((userId, referer) => {
  log.info('Get cache fallback'); // eslint-disable-line
  return service.fetchUserProfile(userId, referer)
});

Looks like Promise.reject does not seems to work.
I get this warning in the console when the service.fetchUserProfile(userId, referer) function returns promise rejection

(node:78791) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): StatusCodeError: 504 - "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>openresty/1.9.7.3</center>\r\n</body>\r\n</html>\r\n"
@lance
Copy link
Member

lance commented Oct 5, 2017

@yharish991 can you provide a reproducible test case? We are currently testing for fallback functions returning a rejected promise here without issue.

@lance lance self-assigned this Oct 5, 2017
@lance lance added the ready label Oct 5, 2017
@lance
Copy link
Member

lance commented Oct 8, 2017

@yharish991 you need to .catch() that rejected promise during the fallback event. A trivial example is here. The warning is not fatal, but will always occur unless the fallback's rejected promise is handled during the fallback event.

In your case, just add a fallback event handler that deals with rejected promises.

@lance lance closed this as completed in fbedb07 Oct 8, 2017
@ghost ghost removed the ready label Oct 8, 2017
@lance
Copy link
Member

lance commented Oct 8, 2017

@yharish991 I have applied a fix that allows you to handle the promise rejection on fallback directly from breaker.fire() instead of only within the fallback event. This will land in the next release, which should be available soon.

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