mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-17 14:35:09 +00:00
Added some exceptions and fleshed out some docstrings
This commit is contained in:
parent
29403e00e0
commit
47b47b85a1
1 changed files with 45 additions and 2 deletions
|
@ -1,9 +1,52 @@
|
|||
#== exceptions.py ==#
|
||||
|
||||
import datetime
|
||||
|
||||
__all__ = (
|
||||
'APIError',
|
||||
'Ratelimited'
|
||||
)
|
||||
|
||||
class APIError(Exception):
|
||||
"""Base level exceptions raised by errors related to any API request or call"""
|
||||
pass
|
||||
"""Base level exceptions raised by errors related to any API request or call."""
|
||||
pass
|
||||
|
||||
class Ratelimited(APIError):
|
||||
"""Raised when the ratelimit from Github is reached or exceeded."""
|
||||
def __init__(self, reset_time: datetime.datetime):
|
||||
formatted = reset_time.strftime(r"%H:%M:%S %A, %d %b")
|
||||
msg = "We're being ratelimited, wait until {}.\nAuthentication raises the ratelimit.".format(formatted)
|
||||
super().__init__(msg)
|
||||
|
||||
class WillExceedRatelimit(APIError):
|
||||
"""Raised when the library predicts the call will exceed the ratelimit, will abort the call by default."""
|
||||
def __init__(self, response, count):
|
||||
msg = 'Performing this action will exceed the ratelimit, aborting.\n{} remaining available calls, calls to make: {}'
|
||||
msg = msg.format(response.header['X-RateLimit-Remaining'], count)
|
||||
super().__init__(msg)
|
||||
|
||||
class UserNotFound(APIError):
|
||||
def __init__(self):
|
||||
msg = 'User not found'
|
||||
super().__init__(msg)
|
||||
|
||||
class OrganizationNotFound(APIError):
|
||||
def __init__(self):
|
||||
msg = 'Organization not found'
|
||||
super().__init__(msg)
|
||||
|
||||
class RepositoryNotFound(APIError):
|
||||
def __init__(self):
|
||||
msg = 'Repository not found'
|
||||
super().__init__(msg)
|
||||
|
||||
class NoAuthProvided(APIError):
|
||||
"""Raised when no proper authorization or invalid authorization is given to the client"""
|
||||
def __init__(self):
|
||||
msg = 'Without authorization, this client doesn\'t have it\'s own repository'
|
||||
super().__init__(msg)
|
||||
|
||||
class ObjectNotFound(APIError):
|
||||
def __init__(self):
|
||||
msg = 'The requested object was not found, ensure spelling is correct before proceeding'
|
||||
super().__init__(msg)
|
Loading…
Add table
Add a link
Reference in a new issue