[docs]classAladhanException(Exception):""" Base exception class for aladhan.py Ideally speaking, this could be caught to handle any exceptions thrown from this library. Attributes ---------- message: str Exception's message. """__slots__=("message",)def__init__(self,message:str=""):self.message=messagesuper().__init__(message)
[docs]classHTTPException(AladhanException):"""Exception that’s thrown when an HTTP request operation fails. Attributes ---------- response: dict API's response. code: int Response's code. """__slots__="response","code"def__init__(self,response,message:str=""):self.response=responseself.code=response.get("code",0)super().__init__(messageorresponse.get("message")or"")@classmethoddeffrom_res(cls,res):return{400:BadRequest,429:TooManyRequests,500:InternalServerError,}.get(res.get("code"),cls)(res)
[docs]classBadRequest(HTTPException):"""Exception that’s thrown for when status code 400 occurs."""
[docs]classTooManyRequests(HTTPException):"""Exception that’s thrown for when status code 429 occurs. .. note:: Current API's rate limit is 14 requests/s. *New in v1.2.0*"""
[docs]classInternalServerError(HTTPException):"""Exception that’s thrown for when status code 500 occurs."""
[docs]classInvalidArgument(AladhanException,ValueError):"""Exception that’s thrown when an argument to a function is invalid some way (e.g. wrong value or wrong type)."""
[docs]classInvalidMethod(InvalidArgument):"""Exception that’s thrown when method argument is invalid."""
[docs]classInvalidTune(InvalidArgument):"""Exception that’s thrown when tune argument is invalid."""
[docs]classInvalidSchool(InvalidArgument):"""Exception that’s thrown when school argument is invalid."""
[docs]classInvalidMidnightMode(InvalidArgument):"""Exception that’s thrown when midnight mode argument is invalid."""
[docs]classInvalidTimezone(InvalidArgument):"""Exception that’s thrown when timezone argument is invalid."""
[docs]classInvalidLatAdjMethod(InvalidArgument):"""Exception that’s thrown when latitude adjustment method argument is invalid."""
[docs]classInvalidAdjustment(InvalidArgument):"""Exception that’s thrown when adjustment argument is invalid."""
[docs]classInvalidShafaq(InvalidArgument):"""Exception that’s thrown when shafaq argument is invalid."""