-
Notifications
You must be signed in to change notification settings - Fork 460
fix(clerk-js): Improve logging for CAPTCHA script loading errors #3374
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/clerk-js': patch | ||
| --- | ||
|
|
||
| Improve logging for CAPTCHA script loading errors |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| import { loadScript } from '@clerk/shared/loadScript'; | ||
| import type { CaptchaWidgetType } from '@clerk/types'; | ||
|
|
||
| import { clerkFailedToLoadThirdPartyScript } from '../core/errors'; | ||
|
|
||
| interface RenderOptions { | ||
| /** | ||
| * Every widget has a sitekey. This sitekey is associated with the corresponding widget configuration and is created upon the widget creation. | ||
|
|
@@ -76,9 +74,12 @@ export async function loadCaptcha(url: string) { | |
| if (!window.turnstile) { | ||
| try { | ||
| await loadScript(url, { defer: true }); | ||
| } catch (_) { | ||
| } catch { | ||
| // Rethrow with specific message | ||
| clerkFailedToLoadThirdPartyScript('Cloudflare Turnstile'); | ||
| console.error('Clerk: Failed to load the CAPTCHA script from the URL: ', url); | ||
| throw { | ||
| captchaError: 'captcha_script_failed_to_load', | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙃 I would suggest we throw a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
| } | ||
| return window.turnstile; | ||
|
|
@@ -112,7 +113,7 @@ export const getCaptchaToken = async (captchaOptions: { | |
| return div; | ||
| }; | ||
|
|
||
| const captcha = await loadCaptcha(scriptUrl); | ||
| const captcha: Turnstile = await loadCaptcha(scriptUrl); | ||
| let retries = 0; | ||
| const errorCodes: (string | number)[] = []; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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 optionalurlparameter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described above, the
clerkFailedToLoadThirdPartyScriptthrows an Error object which is not what we want to do here.