mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-20 07:55:09 +00:00
Rewrote the library
- Only HTTPClient, File and Object exists currently
This commit is contained in:
parent
7bd3d48eab
commit
b23d5b78eb
16 changed files with 1048 additions and 1534 deletions
48
github/errors.py
Normal file
48
github/errors.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
from __future__ import annotations
|
||||
|
||||
__all__ = ("GitHubError", "BaseHTTPError", "HTTPError", "RatelimitReached")
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .utils import human_readable_time_until
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from aiohttp import ClientResponse
|
||||
|
||||
|
||||
class GitHubError(Exception):
|
||||
"""The base class for all errors raised in this library."""
|
||||
|
||||
|
||||
class BaseHTTPError(GitHubError):
|
||||
"""The base class for all HTTP related errors in this library."""
|
||||
|
||||
|
||||
class HTTPError(BaseHTTPError):
|
||||
"""Raised when an HTTP request doesn't respond with a successfull code."""
|
||||
|
||||
def __init__(self, response: ClientResponse, /) -> None:
|
||||
self.method = response.method
|
||||
self.code = response.status
|
||||
self.url = response.url
|
||||
self._response = response
|
||||
|
||||
def __str__(self) -> str:
|
||||
return (
|
||||
f"An HTTP error with the code {self.code} has occured while trying to do a"
|
||||
f" {self.method} request to the URL {self.url}"
|
||||
)
|
||||
|
||||
|
||||
class RatelimitReached(GitHubError):
|
||||
"""Raised when a ratelimit is reached."""
|
||||
|
||||
def __init__(self, reset_time: datetime, /) -> None:
|
||||
self.reset_time = reset_time
|
||||
|
||||
def __str__(self) -> str:
|
||||
return (
|
||||
"The ratelimit has been reached. You can try again in"
|
||||
f" {human_readable_time_until(datetime.now(timezone.utc) - self.reset_time)}"
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue