Unhandled promise rejection error
See original GitHub issueI’m not sure how errors are supposed to be handled. I have the following function that returns a promise:
getFacebookToken(): Promise<string> {
return LoginManager.logInWithPermissions(['public_profile'])
.then((response) => {
if (response.isCancelled) {
// This error is not handled.
throw Error('Request canceled');
} else {
return AccessToken.getCurrentAccessToken();
}
})
.then((response) => response.accessToken)
}
When I use the above with useAsyncTask
and if the promise throws an error, then this is not handled and, also, the task.error
is always null
.
Thank you in advance.
PS. I’m using this in React Native, not ReactJS.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
What is an unhandled promise rejection? - javascript
A rejected promise is like an exception that bubbles up towards the application entry point and causes the root error handler to produce...
Read more >Tracking Unhandled Promise Rejections
When a promise is rejected, it looks for a rejection handler. If it finds one, like in the example above, it calls the...
Read more >Handling those unhandled promise rejections with JS async ...
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was ......
Read more >What is UnhandledPromiseRejectionWarning
The Promise.reject() method returns a Promise object that is rejected with a given reason. The unhandledrejection event is sent to the global scope...
Read more >Unhandled Promise Rejection Warning
The unhandledRejection event is emitted whenever a promise rejection is not handled. “Rejection” is the canonical term for a promise reporting ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you very much, that’s a great solution.
Here’s the Typescript equivalent of your solution in case someone else stumbles upon this:
Thanks for the clarification.
Your understanding is correct. So, we shouldn’t add
catch
there.What I mean is something like this:
It looks annoying to do this every time. As the philosophy of react-hooks-async is composability, we create a new hook instead of modifying useAsyncTask.
Hope it helps.