[docs]classJIRAError(Exception):"""General error raised for all problems in operation of the client."""
[docs]def__init__(self,text:str|None=None,status_code:int|None=None,url:str|None=None,request:Response|None=None,response:Response|None=None,**kwargs,):"""Creates a JIRAError. Args: text (Optional[str]): Message for the error. status_code (Optional[int]): Status code for the error. url (Optional[str]): Url related to the error. request (Optional[requests.Response]): Request made related to the error. response (Optional[requests.Response]): Response received related to the error. **kwargs: Will be used to get request headers. """self.status_code=status_codeself.text=textself.url=urlself.request=requestself.response=responseself.headers=kwargs.get("headers",None)self.log_to_tempfile="PYJIRA_LOG_TO_TEMPFILE"inos.environself.ci_run="GITHUB_ACTION"inos.environ
def__str__(self)->str:t=f"JiraError HTTP {self.status_code}"ifself.url:t+=f" url: {self.url}"details=""ifself.requestisnotNone:ifhasattr(self.request,"headers"):details+=f"\n\trequest headers = {self.request.headers}"ifhasattr(self.request,"text"):details+=f"\n\trequest text = {self.request.text}"ifself.responseisnotNone:ifhasattr(self.response,"headers"):details+=f"\n\tresponse headers = {self.response.headers}"ifhasattr(self.response,"text"):details+=f"\n\tresponse text = {self.response.text}"ifself.log_to_tempfile:# Only log to tempfile if the option is set._,file_name=tempfile.mkstemp(suffix=".tmp",prefix="jiraerror-")withopen(file_name,"w")asf:t+=f" details: {file_name}"f.write(details)else:# Otherwise, just return the error as usualifself.text:t+=f"\n\ttext: {self.text}"t+=f"\n\t{details}"returnt
[docs]classNotJIRAInstanceError(Exception):"""Raised in the case an object is not a JIRA instance."""
[docs]def__init__(self,instance:Any):msg=("The first argument of this function must be an instance of type "f"JIRA. Instance Type: {instance.__class__.__name__}")super().__init__(msg)