[docs]classUnsupportedRequestError(ValueError,Error):""" UnsupportedRequestError is a named Exception class representing any Error from the runZero API which cannot be properly interpreted into a friendlier form. """def__init__(self,message:str):super().__init__(message)
[docs]classErrInfo(RFC7807Error):"""runZero's implementation of RFC7807 JSON error description"""def__init__(self,detail:str,status:int,title:str):super().__init__(title=title,status=status,detail=detail)def__repr__(self)->str:returnf"Error: Details:{self.detail}, Status:{self.status}, Title:{self.title}"
[docs]classClientError(APIError):""" ClientError is a named Exception class for holding 400 level http status code messages. :param error_info: :class:`.ErrInfo`, optional which holds message data parsed from the server's response. :type error_info: ErrInfo :param unparsed_response: a string which holds the unparsed response body. :type unparsed_response: str, optional :param message: A top-level error description. The default value None provides a reasonable message. """def__init__(self,message:Optional[str]=None,unparsed_response:Optional[str]=None,error_info:Optional[ErrInfo]=None,):"""Constructor method"""ifmessage:message=message.strip()ifnotmessage:message="The request was rejected by the server."super().__init__(message)self.error_info:Optional[ErrInfo]=error_infoself.unparsed_response:Optional[str]=unparsed_responsedef__str__(self)->str:"""Provide a friendly, printable error string. Otherwise, only 'message' is printed."""out=f"{super().__str__()}".strip()ifself.error_info:out=f"{out}: {self.error_info}"returnout
[docs]classServerError(APIError):""" ServerError is a named Exception class for holding 500 level http status code messages. A ServerError indicates nothing about the way the request was performed. The server cannot complete the task. You should retry or abort. :param error_info: :class:`.ErrInfo`, optional which holds message data parsed from the server's response. :type error_info: ErrInfo :param message: A top-level error description. The default value None provides a reasonable message. :param unparsed_response: optional string which holds the unparsed response body. :type unparsed_response: str, optional """def__init__(self,message:Optional[str]=None,unparsed_response:Optional[str]=None,error_info:Optional[ErrInfo]=None,):"""Constructor method"""ifmessage:message=message.strip()ifnotmessage:message="The server encounter an error or is unable to process the request."super().__init__(message)self.error_info:Optional[ErrInfo]=error_infoself.unparsed_response:Optional[str]=unparsed_responsedef__str__(self)->str:"""Provide a friendly, printable error string. Otherwise, only 'message' is printed."""out=f"{super().__str__()}"ifself.error_info:out=f"{out}: {self.error_info}"returnout
[docs]classAuthError(APIError):""" AuthError is a named Exception class for authentication issues with the runZero SDK client Common types of authentication issues are: * Incorrect credentials * Misconfigured credentials * Missing credentials """pass
[docs]classRateLimitError(APIError):""" RateLimitError is a named Exception class errors resulting from API rate limiting. See https://www.runzero.com/docs/leveraging-the-api/#api-client-credentials for details. Consider an exponential backoff retry, or a more calculated approach by examining the returned numbers. :param message: A top-level error description. The default value None provides a reasonable message. :param unparsed_response: optional string which holds the unparsed response body. :type unparsed_response: str, optional :param rate_limit_information: a RateLimitInformation object which holds the rate limit data :type rate_limit_information: RateLimitInformation """def__init__(self,rate_limit_information:RateLimitInformation,message:Optional[str]=None,unparsed_response:Optional[str]=None,):"""Constructor method"""ifnotmessage:message=("Too many API requests for licensed rate limit. See runZero documentation for details on API ""rate limiting.")super().__init__(message)self.message=messageself.unparsed_response:Optional[str]=unparsed_responseself.rate_limit_information:RateLimitInformation=rate_limit_informationdef__str__(self)->str:returnf"{self.message} Rate limit information: {self.rate_limit_information}"
[docs]classUnknownAPIError(APIError):""" UnknownAPIError is a named Exception class raised when the response indicates a structured error message that cannot be parsed. Effort is made to receive and interpret errors returned from runZero services. These errors should be rare to non-existent. :param message: A top-level error description. The default value None provides a reasonable message. :param unparsed_response: optional string which holds the unparsed response body. :type unparsed_response: str, optional """def__init__(self,message:Optional[str]=None,unparsed_response:Optional[str]=None):"""Constructor method"""ifnotmessage:message="The server encounter an error or is unable to process the request."super().__init__(message)self.unparsed_response:Optional[str]=unparsed_response
[docs]classCommunicationError(Error):""" CommunicationError is a named Exception class raised when an API request to runZero service cannot complete due to a protocol-level error. """pass
[docs]classConnError(Error,ConnectionError):""" ConnError is a named Exception class raised when an API request to runZero service cannot complete due to a packet-level error. """pass
[docs]classConnTimeoutError(Error,TimeoutError):""" ConnTimeoutError is a named Exception class raised when an API request to runZero service cannot complete due a failure to create or maintain a connection to a runZero resource. The timeout value of the Client can be adjusted. """pass