mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-16 06:05:00 +00:00
Move utils.error_from_request to errors.py and fix circular imports
This commit is contained in:
parent
cad7916da6
commit
f71c0db13b
4 changed files with 11 additions and 13 deletions
|
@ -25,7 +25,7 @@ SOFTWARE.
|
|||
|
||||
__title__ = "GitHub-API-Wrapper"
|
||||
__authors__ = ("VarMonke", "sudosnok", "contributors")
|
||||
__version__ = "2.0a"
|
||||
__version__ = "2.0.0a"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022-present VarMonke, sudosnok & contributors"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
__all__ = ("GitHubError", "BaseHTTPError", "HTTPError", "RatelimitReached")
|
||||
__all__ = ("GitHubError", "BaseHTTPError", "HTTPError", "RatelimitReached", "error_from_request")
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from typing import TYPE_CHECKING
|
||||
|
@ -46,3 +46,7 @@ class RatelimitReached(GitHubError):
|
|||
"The ratelimit has been reached. You can try again in"
|
||||
f" {human_readable_time_until(datetime.now(timezone.utc) - self.reset_time)}"
|
||||
)
|
||||
|
||||
def error_from_request(request: ClientResponse, /) -> BaseHTTPError:
|
||||
# TODO: Make specific errrors
|
||||
return HTTPError(request)
|
||||
|
|
|
@ -9,10 +9,10 @@ import time
|
|||
from datetime import datetime, timezone
|
||||
from typing import TYPE_CHECKING, Any, Awaitable, Dict, List, Literal, NamedTuple, Optional, Union
|
||||
|
||||
from aiohttp import ClientSession, TraceConfig
|
||||
from aiohttp import ClientSession, TraceConfig, __version__ as aiohttp_verrsion
|
||||
|
||||
from .. import __version__
|
||||
from ..utils import error_from_request, human_readable_time_until
|
||||
from ..utils import human_readable_time_until
|
||||
from ..errors import error_from_request
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from types import SimpleNamespace
|
||||
|
@ -112,7 +112,7 @@ class HTTPClient:
|
|||
headers.setdefault(
|
||||
"User-Agent",
|
||||
"GitHub-API-Wrapper (https://github.com/Varmonke/GitHub-API-Wrapper) @"
|
||||
f" {__version__} CPython/{platform.python_version()} aiohttp/{__version__}",
|
||||
f" 2.0.0a CPython/{platform.python_version()} aiohttp/{aiohttp_verrsion}",
|
||||
)
|
||||
|
||||
self._rates = Ratelimits(None, None, None, None, None)
|
||||
|
@ -202,6 +202,7 @@ class HTTPClient:
|
|||
if 200 <= request.status <= 299:
|
||||
return await request.json()
|
||||
|
||||
print(await request.json())
|
||||
raise error_from_request(request)
|
||||
|
||||
# === ROUTES === #
|
||||
|
|
|
@ -11,8 +11,6 @@ __all__ = (
|
|||
from base64 import b64encode
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from .errors import HTTPError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
@ -39,8 +37,3 @@ def repr_dt(time: datetime, /) -> str:
|
|||
|
||||
def bytes_to_b64(content: str, /) -> str:
|
||||
return b64encode(content.encode("utf-8")).decode("ascii")
|
||||
|
||||
|
||||
def error_from_request(request: ClientResponse, /) -> BaseHTTPError:
|
||||
# TODO: Make specific errrors
|
||||
return HTTPError(request)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue