Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ogd/apis/models/APIResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ def Status(self) -> ResponseStatus:
:rtype: ResponseStatus
"""
return self._status
@property
def OK(self) -> bool:
"""Property indicating whether the APIResponse was successful or not.

Technically, this includes both a true "OK" response and any other 200-range response.

:return: True if the APIResponse status is in the 200 range, otherwise False.
:rtype: bool
"""
return self.Status in ResponseStatus.SuccessStatuses()

@property
def AsDict(self):
Expand Down
13 changes: 11 additions & 2 deletions src/ogd/apis/models/enums/ResponseStatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,23 @@ class ResponseStatus(IntEnum):
INSUFFICIENT_STORAGE = 507
LOOP_DETECTED = 508

@staticmethod
def SuccessStatuses() -> Set["ResponseStatus"]:
"""Gets the set of valid 400-level "client" error responses.

:return: The set of valid 400-level "client" error responses.
:rtype: Set[ResponseStatus]
"""
return {status for status in set(ResponseStatus) if status in range(200, 300)}

@staticmethod
def ClientErrors() -> Set["ResponseStatus"]:
"""Gets the set of valid 400-level "client" error responses.

:return: The set of valid 400-level "client" error responses.
:rtype: Set[ResponseStatus]
"""
return {status for status in set(ResponseStatus) if status in range(400, 499)}
return {status for status in set(ResponseStatus) if status in range(400, 500)}

@staticmethod
def ServerErrors() -> Set["ResponseStatus"]:
Expand All @@ -97,7 +106,7 @@ def ServerErrors() -> Set["ResponseStatus"]:
:return: The set of valid 500-level "server" error responses.
:rtype: Set[ResponseStatus]
"""
return {status for status in set(ResponseStatus) if status in range(500, 599)}
return {status for status in set(ResponseStatus) if status in range(500, 600)}

def __str__(self):
"""Stringify function for ResponseStatus objects.
Expand Down
Loading