Skip to content

A platform for community discussion. Free, open, simple.

DEV: Improve error messaging (#24099)

Penar Musaraje231ed21539c
diff --git a/app/assets/javascripts/discourse/app/lib/webauthn.js b/app/assets/javascripts/discourse/app/lib/webauthn.js
index a48aedc28f3..94e47de4e94 100644
--- a/app/assets/javascripts/discourse/app/lib/webauthn.js
+++ b/app/assets/javascripts/discourse/app/lib/webauthn.js
@@ -146,15 +146,31 @@ export async function getPasskeyCredential(
userHandle: bufferToBase64(credential.response.userHandle),
};
} catch (error) {
- if (error.name === "NotAllowedError") {
- return errorCallback(I18n.t("login.security_key_not_allowed_error"));
- } else if (error.name === "AbortError") {
+ if (error.name === "AbortError") {
// no need to show an error when the cancelling a pending ceremony
// this happens when switching from the conditional method (username input autofill)
// to the optional method (login button) or vice versa
return null;
+ }
+
+ if (mediation === "conditional") {
+ // The conditional method gets triggered in the background
+ // it's not helpful to show errors for it in the UI
+ // eslint-disable-next-line no-console
+ console.error(error);
+ return null;
+ }
+
+ if (error.name === "NotAllowedError") {
+ return errorCallback(I18n.t("login.security_key_not_allowed_error"));
+ } else if (error.name === "SecurityError") {
+ return errorCallback(
+ I18n.t("login.passkey_security_error", {
+ message: error.message,
+ })
+ );
} else {
- return errorCallback(error);
+ return errorCallback(error.message);
}
}
}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index df17fe18e17..aa4d48cefb7 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2203,6 +2203,7 @@ en:
security_key_no_matching_credential_error: "No matching credentials could be found in the provided security key."
security_key_support_missing_error: "Your current device or browser does not support the use of security keys. Please use a different method."
security_key_invalid_response_error: "The security key authentication process failed due to an invalid response."
+ passkey_security_error: "There was a security error: %{message}"
email_placeholder: "Email / Username"
caps_lock_warning: "Caps Lock is on"
error: "Unknown error"