"""Custom exceptions thrown in qnexus usage."""importjsonfromtypingimportOptional
[docs]classAuthenticationError(Exception):"Raised when there is an issue authenticating with the Nexus API."
[docs]classResourceFetchFailed(Exception):""" Raised when a resource cannot be fetched from the platform to be read, or when expected data wasn't found on an object. """def__init__(self,message:str,status_code:Optional[int]=None)->None:self.message=messageself.status_code=status_codeself.err=f"Failed to fetch resource with status code: {self.status_code}\n"try:msg_data=json.loads(message)self.err+=f"Message: {msg_data['message']}"forfld,valinmsg_data.items():iffld!="message":self.err+=f"\n{fld}: {val}"exceptjson.JSONDecodeError:self.err+=f"Message: {message}"super().__init__(self.err)
[docs]classZeroMatches(Exception):"""Raised when a ``get`` call finds no matches."""
[docs]classNoUniqueMatch(Exception):"""Raised when a ``get`` call finds more than one match."""
[docs]classJobError(Exception):"""Raised when a Nexus Job has errored."""
[docs]classResourceCreateFailed(Exception):"""Raised when a resource couldn't be created on the platform."""def__init__(self,message:str,status_code:Optional[int]=None)->None:self.message=messageself.status_code=status_codeself.err=("Failed to create resource with status code: "f"{self.status_code}, message: {self.message}")super().__init__(self.err)
[docs]classResourceDeleteFailed(Exception):"""Raised when a resource couldn't be deleted on the platform."""def__init__(self,message:str,status_code:Optional[int]=None)->None:self.message=messageself.status_code=status_codeself.err=("Failed to delete resource with status code: "f"{self.status_code}, message: {self.message}")super().__init__(self.err)
[docs]classResourceUpdateFailed(Exception):"""Raised when a resource cannot be updated on the platform."""def__init__(self,message:str,status_code:Optional[int]=None)->None:self.message=messageself.status_code=status_codeself.err=("Failed to update resource with status code: "f"{self.status_code}, message: {self.message}")super().__init__(self.err)
[docs]classIncompatibleResultVersion(Exception):"""Raised when the user tries to get results in a version that's not possible"""