diff --git a/addons/website_cf_turnstile/__manifest__.py b/addons/website_cf_turnstile/__manifest__.py
index 1c56be34342..d7306fdc322 100644
--- a/addons/website_cf_turnstile/__manifest__.py
+++ b/addons/website_cf_turnstile/__manifest__.py
@@ -15,6 +15,7 @@ This module implements Cloudflare Turnstile so that you can prevent bot spam on
'assets': {
'web.assets_frontend': [
'website_cf_turnstile/static/src/js/turnstile.js',
+ 'website_cf_turnstile/static/src/js/error_handler.js',
],
},
'license': 'LGPL-3',
diff --git a/addons/website_cf_turnstile/static/src/js/error_handler.js b/addons/website_cf_turnstile/static/src/js/error_handler.js
new file mode 100644
index 00000000000..ed42ebee8fa
--- /dev/null
+++ b/addons/website_cf_turnstile/static/src/js/error_handler.js
@@ -0,0 +1,23 @@
+/** @odoo-module */
+
+import { ErrorDialog } from "@web/core/errors/error_dialogs";
+import { _t } from "@web/core/l10n/translation";
+import { registry } from "@web/core/registry";
+
+function turnstileErrorHandler(env, error) {
+ if (error.message.includes("Turnstile Error")) {
+ env.services.dialog.add(ErrorDialog, {
+ name: _t("Cloudflare Turnstile Error"),
+ traceback: _t(
+ `There was an error with Cloudflare Turnstile, the captcha system.\n` +
+ `Please make sure your credentials for this service are properly set up.\n` +
+ `The error code is: %s.\n` +
+ `You can find more information about this error code here: https://developers.cloudflare.com/turnstile/reference/errors.`,
+ error.event.error.code
+ ),
+ });
+ return true;
+ }
+}
+
+registry.category("error_handlers").add("turnstile_error_handler", turnstileErrorHandler);
diff --git a/addons/website_cf_turnstile/static/src/js/turnstile.js b/addons/website_cf_turnstile/static/src/js/turnstile.js
index 596d8d2a6c5..fc2c3d8770f 100644
--- a/addons/website_cf_turnstile/static/src/js/turnstile.js
+++ b/addons/website_cf_turnstile/static/src/js/turnstile.js
@@ -18,7 +18,17 @@ publicWidget.registry.s_website_form.include({
data-appearance="${mode}"
data-response-field-name="turnstile_captcha"
data-sitekey="${session.turnstile_site_key}"
+ data-error-callback="throwTurnstileError"
>
+
`).insertAfter('.s_website_form_send, .o_website_form_send');
}