Skip to content

Commit

Permalink
init Error dataclass def
Browse files Browse the repository at this point in the history
  • Loading branch information
jafermarq committed Feb 28, 2024
1 parent 2f4d839 commit daa23f1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/py/flwr/common/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,30 +220,40 @@ def content(self, value: RecordSet) -> None:
"""Set content."""
self._content = value

@property
def error(self) -> Error:
"""Error captured by this message."""
return self._error

@error.setter
def error(self, value: Error) -> None:
"""Set error."""
self._error = value

def construct_error_message(
self,
error_code: int,
ttl: str,
error_reason: str | None = None,
content: RecordSet | None = None,
ttl: str = "",
) -> Message:
"""Construct valid response message indicating an error happened.
Parameters
----------
error_code : int
Error code.
ttl : str
Time-to-live for this message.
error_reason : Optional[str]
A reason for why the error arised (e.g. an exception stack-trace)
content : Optional[RecordSet]
The content for the reply message.
ttl : str (default: "")
Time-to-live for this message.
"""
message_content = content if content else RecordSet()
message = self.create_reply(content=message_content, ttl=ttl)
# Set error
message._error = Error(code=error_code, reason=error_reason)
message.error = Error(code=error_code, reason=error_reason)
return message

def create_reply(self, content: RecordSet, ttl: str) -> Message:
Expand Down

0 comments on commit daa23f1

Please sign in to comment.