From 570dee516d26c56c3ce1c6e02c7b1febf9b2ea3d Mon Sep 17 00:00:00 2001 From: hyejiyu Date: Tue, 24 Sep 2024 04:07:18 +0900 Subject: [PATCH] added Exception Handling: JSONDecodeError --- messagequeue/consumer/homeplus_consumer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/messagequeue/consumer/homeplus_consumer.py b/messagequeue/consumer/homeplus_consumer.py index e438aab..7e3f37a 100644 --- a/messagequeue/consumer/homeplus_consumer.py +++ b/messagequeue/consumer/homeplus_consumer.py @@ -51,8 +51,12 @@ def callback(ch, method, properties, body): cnt += 1 reset_timer() # formatted_date = now.strftime("%Y-%m-%d %H:%M:%S") - message_str = body.decode('utf-8') - message_json = json.loads(message_str) + try: + message_str = body.decode('utf-8') + message_json = json.loads(message_str) + except json.JSONDecodeError as e: + print(f"Failed to decode JSON: {e}\n Received message: {message_str}"} + pass category_name = message_json['category_name'] product_id = message_json['product_id'] price = message_json['price']