Skip to content

Commit

Permalink
added Exception Handling: JSONDecodeError
Browse files Browse the repository at this point in the history
  • Loading branch information
HyejiYu committed Sep 23, 2024
1 parent 8855fdb commit 570dee5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions messagequeue/consumer/homeplus_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 570dee5

Please sign in to comment.