The reCaptcha v3 documentation gives good examples on how to retrieve a token and make use of it -
grecaptcha.ready(function() {
grecaptcha.execute('_reCAPTCHA_site_key_', {action: 'homepage'}).then(function(token) {
...
});
});
What they don't show is how to handle a rejection. I use Sentry for client-side error logging, and noticed that since I began using reCaptcha it is recording quite a few "UnhandledRejection - Non-Error promise rejection". Values that are sent back in the rejection include "Timeout" and "null".
My question is two-fold -
- Why do these rejections occur in reCaptcha? I assume it is when it fails to generate a token, but documentation doesn't explain why this would happen.
- How would I handle/squash the rejections when I don't want them being caught by Sentry? I attempted to add a catch() after .then() off .execute(), but it doesn't seem to return actual Promise? Can only use .then(), else get an error on load of the page.
Example resulting in 'catch not defined' -
.then(function(token) {
...
}).catch(function(e) { //squash });