From 2a2e5d03e99b454c36f25718a8f308a5c5ee5511 Mon Sep 17 00:00:00 2001 From: "mw-middleware-labs-sandbox[bot]" <224139880+mw-middleware-labs-sandbox[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2026 21:12:07 +0000 Subject: [PATCH 1/2] fix: Fix KeyError in user_profile function with safe dictionary access and proper error handling --- flask/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flask/app.py b/flask/app.py index c30b439..63dbe3d 100644 --- a/flask/app.py +++ b/flask/app.py @@ -60,9 +60,9 @@ def generate_exception(): @app.route('/user/') def user_profile(username): print(f"User profile requested for {username}") - test = user_data[username] + test = user_data.get(username) if not test: - raise + return jsonify({"error": "User not found"}), 404 return jsonify({"message": f"Profile for {username}", "data": test}) @app.route('/process', methods=['POST']) From 05b5cf5bf707cf4a0cd336affcce75cc6dd7629e Mon Sep 17 00:00:00 2001 From: "mw-middleware-labs-sandbox[bot]" <224139880+mw-middleware-labs-sandbox[bot]@users.noreply.github.com> Date: Tue, 17 Mar 2026 08:38:59 +0000 Subject: [PATCH 2/2] fix: Fix KeyError in user_profile function with safe dictionary access and error handling