From d4cf3d39a7b86c86c98b37a32f2dd95dfcd65532 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Thu, 17 Sep 2026 15:17:59 +0800 Subject: [PATCH] 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__)}})