From d4cf3d39a7b86c86c98b37a32f2dd95dfcd65532 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Thu, 17 Sep 2026 15:17:59 +0800 Subject: [PATCH 1/2] fix(recaptcha): demo views answered 500 instead of their JSON error body `except ValueError or Exception as e` reads like it catches both, but `or` returns the first truthy operand, so the handler only ever caught ValueError. Anything else escaped it: the assessment call raises google.api_core errors (PermissionDenied, InvalidArgument, ...) which are not ValueError, and a request body without "token" raises KeyError before the call is even made. All four submit views were written to answer with {"data": {"error_msg": ...}} in that case, so they were returning a 500 error page instead. Exception already covers ValueError, so the tuple is not needed. Signed-off-by: rootkiller6788 --- recaptcha_enterprise/demosite/app/urls.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/recaptcha_enterprise/demosite/app/urls.py b/recaptcha_enterprise/demosite/app/urls.py index b1e54691758..5426397c73a 100644 --- a/recaptcha_enterprise/demosite/app/urls.py +++ b/recaptcha_enterprise/demosite/app/urls.py @@ -101,7 +101,7 @@ def on_signup() -> Response: } } ) - except ValueError or Exception as e: + except Exception as e: return jsonify({"data": {"error_msg": str(e.__dict__)}}) @@ -150,7 +150,7 @@ def on_login() -> Response: } } ) - except ValueError or Exception as e: + except Exception as e: return jsonify({"data": {"error_msg": str(e.__dict__)}}) @@ -198,7 +198,7 @@ def on_store_checkout() -> Response: } } ) - except ValueError or Exception as e: + except Exception as e: return jsonify({"data": {"error_msg": str(e.__dict__)}}) @@ -246,7 +246,7 @@ def on_comment_submit() -> Response: } } ) - except ValueError or Exception as e: + except Exception as e: return jsonify({"data": {"error_msg": str(e.__dict__)}}) From ab71d28b4b73f61ed4ca6055f3e66a2ba53295e2 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Sun, 8 Nov 2026 15:00:05 +0800 Subject: [PATCH 2/2] fix(recaptcha): return the error message, not the exception __dict__ str(e.__dict__) serializes the exception's attribute dictionary, which is '{}' for exceptions that carry no attributes (e.g. KeyError from a payload without "token"), and a noisy internal dict for google.api_core errors. The demo's error_msg should be the exception's message, so use str(e). Addresses the review comment on #14635. Signed-off-by: rootkiller6788 --- recaptcha_enterprise/demosite/app/urls.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/recaptcha_enterprise/demosite/app/urls.py b/recaptcha_enterprise/demosite/app/urls.py index 5426397c73a..8d7f7f69e0f 100644 --- a/recaptcha_enterprise/demosite/app/urls.py +++ b/recaptcha_enterprise/demosite/app/urls.py @@ -102,7 +102,7 @@ def on_signup() -> Response: } ) except Exception as e: - return jsonify({"data": {"error_msg": str(e.__dict__)}}) + return jsonify({"data": {"error_msg": str(e)}}) # Return login template. @@ -151,7 +151,7 @@ def on_login() -> Response: } ) except Exception as e: - return jsonify({"data": {"error_msg": str(e.__dict__)}}) + return jsonify({"data": {"error_msg": str(e)}}) # Return store template. @@ -199,7 +199,7 @@ def on_store_checkout() -> Response: } ) except Exception as e: - return jsonify({"data": {"error_msg": str(e.__dict__)}}) + return jsonify({"data": {"error_msg": str(e)}}) # Return comment template. @@ -247,7 +247,7 @@ def on_comment_submit() -> Response: } ) except Exception as e: - return jsonify({"data": {"error_msg": str(e.__dict__)}}) + return jsonify({"data": {"error_msg": str(e)}}) # Classify the action as BAD/ NOT_BAD based on conditions specified.