generated from pufereq/python-template
feat(message.py): raise ValueError if invalid json in Message.from_bytes()
This commit is contained in:
@@ -87,7 +87,12 @@ class Message:
|
||||
Returns:
|
||||
Message: The created message.
|
||||
"""
|
||||
return cls.from_dict(json.loads(data))
|
||||
try:
|
||||
json_data = json.loads(data)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError("Invalid JSON data") from e
|
||||
|
||||
return cls.from_dict(json_data)
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes) -> Message:
|
||||
|
||||
Reference in New Issue
Block a user