Skip to content

fix(clerk-js): Improve logging for CAPTCHA script loading errors#3374

Merged
anagstef merged 3 commits intomainfrom
stefanos/core-2247-investigate-if-we-can-expose-more-information-on-turnstile
May 13, 2024
Merged

fix(clerk-js): Improve logging for CAPTCHA script loading errors#3374
anagstef merged 3 commits intomainfrom
stefanos/core-2247-investigate-if-we-can-expose-more-information-on-turnstile

Conversation

@anagstef
Copy link
Copy Markdown
Member

@anagstef anagstef commented May 13, 2024

Description

This PR adds a console.error on every CAPTCHA error.

Also, when script loading fails, we log it in the FAPI, meaning that the /sign_ups API call will be executed and will include the following value:

captchaError: 'captcha_script_failed_to_load'

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 13, 2024

🦋 Changeset detected

Latest commit: e30bde7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

console.error('Clerk: Failed to load the CAPTCHA script from the URL: ', url);
throw {
captchaError: 'captcha_script_failed_to_load',
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 I would suggest we throw a ClerkError (an existing one or create a new one) instead of throwing an object. In order to provide a better error handling in the future i think that we will need to use our Error classes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit complicated! We don't want everything to throw here. We actually send the captchaError error value to the FAPI.

} catch (_) {
} catch {
// Rethrow with specific message
clerkFailedToLoadThirdPartyScript('Cloudflare Turnstile');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 Why did we drop the usage of clerkFailedToLoadThirdPartyScript ? Couldn't we enhance it with an optional url parameter?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described above, the clerkFailedToLoadThirdPartyScript throws an Error object which is not what we want to do here.

Comment thread packages/clerk-js/src/core/resources/SignUp.ts Outdated
@agis
Copy link
Copy Markdown
Member

agis commented May 13, 2024

I think it's worth noting that, even more important that the console log that this PR achieves, is the request that we'll make to FAPI's signUp.create in case there's an error loading the script - this was not the case before this PR. I'm mentioning this for reviewers, because it might not be apparent how this is achieved by looking at the code changes.

@anagstef anagstef merged commit 34befee into main May 13, 2024
@anagstef anagstef deleted the stefanos/core-2247-investigate-if-we-can-expose-more-information-on-turnstile branch May 13, 2024 17:34
@clerk-cookie clerk-cookie mentioned this pull request May 13, 2024
anagstef added a commit that referenced this pull request May 15, 2024
* fix(clerk-js): Improve logging for CAPTCHA script loading errors

* fix(clerk-js): Remove the generic CAPTCHA console error

(cherry picked from commit 34befee)
anagstef added a commit that referenced this pull request May 15, 2024
…lure logging (#3384)

* fix(clerk-js): Improve logging for CAPTCHA script loading errors (#3374)

* fix(clerk-js): Improve logging for CAPTCHA script loading errors

* fix(clerk-js): Remove the generic CAPTCHA console error

(cherry picked from commit 34befee)

* fix(clerk-js): Use first-party cookies when running on Cypress (#3245)

* fix(clerk-js): Use first-party cookies when running on Cypress

* fix(clerk-js): Create isCypress util

(cherry picked from commit 7b213d5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants