Document that error responses can have a result object after all
Also document some custom result types
This commit is contained in:
parent
dcf17fd40a
commit
a817049e12
@ -28,7 +28,7 @@ class CommandException(Exception):
|
||||
In the case that different status codes map to the same error subclass, the status code
|
||||
can be retrieved from the "status" property.
|
||||
"""
|
||||
# NOTE unsuccessful responses do not set a result, hence using RootCommandResult here
|
||||
# TODO Handle result object
|
||||
# TODO Print _unrecognized?
|
||||
self.status = result.status
|
||||
self.message = _status_code_message_map.get(self.status, self._default_message)
|
||||
|
@ -93,6 +93,7 @@ class RootCommandResult(ResponseState):
|
||||
ResultType = TypeVar("ResultType", bound=Serializable)
|
||||
|
||||
def ResultListType(result_type: Type[ResultType]):
|
||||
"""Custom type for setting a result to a list of serializable objects."""
|
||||
class _ResultListType(list[result_type], Serializable):
|
||||
def serialize(self) -> list[JSON]:
|
||||
return [v.serialize() for v in self]
|
||||
@ -104,6 +105,7 @@ def ResultListType(result_type: Type[ResultType]):
|
||||
return _ResultListType
|
||||
|
||||
def ResultRawType(result_type: Type):
|
||||
"""Custom type for setting a result to a primitive."""
|
||||
class _ResultRawType(result_type, Serializable):
|
||||
def serialize(self) -> result_type:
|
||||
return self
|
||||
@ -132,6 +134,7 @@ def deserialize_result(
|
||||
) -> Union[CommandResultDoneValue[ResultType], RootCommandResult]:
|
||||
"""Returns equivalent of CommandResult<T>. Does no consistency checking on success & result properties."""
|
||||
if "result" in data and data.get("success"):
|
||||
# TODO Handle result object in unsuccessful response
|
||||
# TODO Allow arbitrary result object?
|
||||
return CommandResultDoneValue.deserialize_result(result_type, data)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user