47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
class ResponseStatus:
|
|
|
|
def __init__(self, code: int=0, message:str="", error_text:str=""):
|
|
self._code = code
|
|
self._message = message
|
|
self._error_text = error_text
|
|
|
|
@property
|
|
def error_text(self):
|
|
"""Get the status code"""
|
|
return self._error_text
|
|
|
|
@error_text.setter
|
|
def error_text(self, value):
|
|
self._error_text = value
|
|
|
|
# Status Code property with validation
|
|
@property
|
|
def code(self):
|
|
"""Get the status code"""
|
|
return self._code
|
|
|
|
@code.setter
|
|
def code(self, value):
|
|
"""Set the status code with validation"""
|
|
if not isinstance(value, int):
|
|
raise TypeError("code must be an integer")
|
|
if value < 0 or value > 599:
|
|
raise ValueError("code must be between 0 and 599")
|
|
self._code = value
|
|
|
|
# Status Message property with validation
|
|
@property
|
|
def message(self):
|
|
"""Get the status message"""
|
|
return self._message
|
|
|
|
@message.setter
|
|
def message(self, value):
|
|
"""Set the status message with validation"""
|
|
if not isinstance(value, str):
|
|
raise TypeError("message must be a string")
|
|
self._message = value
|
|
|
|
def __repr__(self):
|
|
return f'ResponseStatus(code={self.code}, message={self.message})'
|