From 71c1b2f9ce8e8582b9c81e95603749c802d06951 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 16 Nov 2025 07:27:47 +0000 Subject: [PATCH] Fix HTTP 500 error in ObjectSerializer by handling non-serializable objects gracefully Co-authored-by: alexta69 <7450369+alexta69@users.noreply.github.com> --- app/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index 73132a7..2d71eac 100644 --- a/app/main.py +++ b/app/main.py @@ -123,10 +123,14 @@ class ObjectSerializer(json.JSONEncoder): elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes)): try: return list(obj) - except: - pass - # Fall back to default behavior - return json.JSONEncoder.default(self, obj) + except (TypeError, ValueError, RuntimeError): + # If conversion to list fails, log a warning and return a placeholder + log.warning(f"Failed to convert {type(obj).__name__} to list, using string representation") + return str(obj) + # For objects that can't be serialized, return their string representation + # This prevents HTTP 500 errors while still providing useful information + log.warning(f"Object of type {type(obj).__name__} is not directly JSON serializable, using string representation") + return str(obj) serializer = ObjectSerializer() app = web.Application()