mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-22 06:17:57 +00:00
🐛 Fix RegionNotSupported
Error
This commit is contained in:
parent
db76c21d4a
commit
fc2faa805f
@ -7,7 +7,7 @@ from httpx import AsyncClient, TimeoutException, Response, HTTPError, Timeout
|
|||||||
|
|
||||||
from simnet.client.cookies import Cookies
|
from simnet.client.cookies import Cookies
|
||||||
from simnet.client.headers import Headers
|
from simnet.client.headers import Headers
|
||||||
from simnet.errors import TimedOut, NetworkError, BadRequest, raise_for_ret_code
|
from simnet.errors import TimedOut, NetworkError, BadRequest, raise_for_ret_code, NotSupported
|
||||||
from simnet.utils.cookies import parse_cookie
|
from simnet.utils.cookies import parse_cookie
|
||||||
from simnet.utils.ds import generate_dynamic_secret, DSType, hex_digest
|
from simnet.utils.ds import generate_dynamic_secret, DSType, hex_digest
|
||||||
from simnet.utils.enum_ import Region, Game
|
from simnet.utils.enum_ import Region, Game
|
||||||
@ -308,6 +308,8 @@ class BaseClient(AsyncContextManager["BaseClient"]):
|
|||||||
if response.is_error or ret_code != 0:
|
if response.is_error or ret_code != 0:
|
||||||
raise_for_ret_code(data)
|
raise_for_ret_code(data)
|
||||||
return data["data"]
|
return data["data"]
|
||||||
|
if response.status_code == 404:
|
||||||
|
raise NotSupported("API not supported or has been removed.")
|
||||||
raise BadRequest(status_code=response.status_code, message=response.text)
|
raise BadRequest(status_code=response.status_code, message=response.text)
|
||||||
|
|
||||||
async def request_lab(
|
async def request_lab(
|
||||||
|
@ -44,7 +44,7 @@ class BaseDiaryClient(BaseClient):
|
|||||||
params = params or {}
|
params = params or {}
|
||||||
|
|
||||||
url = (
|
url = (
|
||||||
DETAIL_LEDGER_URL.get_url(self.region)
|
DETAIL_LEDGER_URL.get_url(self.region, game)
|
||||||
if detail
|
if detail
|
||||||
else INFO_LEDGER_URL.get_url(
|
else INFO_LEDGER_URL.get_url(
|
||||||
self.region,
|
self.region,
|
||||||
|
@ -61,6 +61,15 @@ class URL(_URL):
|
|||||||
"""
|
"""
|
||||||
return URL(urljoin(str(self) + "/", str(URL(url))))
|
return URL(urljoin(str(self) + "/", str(URL(url))))
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
"""Return True if the URL is not empty.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if the URL is not empty.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return str(self) != ""
|
||||||
|
|
||||||
|
|
||||||
class BaseRoute:
|
class BaseRoute:
|
||||||
"""A base class for defining routes with useful metadata."""
|
"""A base class for defining routes with useful metadata."""
|
||||||
@ -241,9 +250,15 @@ CALCULATOR_URL = InternationalRoute(
|
|||||||
chinese="https://api-takumi.mihoyo.com/event/e20200928calculate/v1/",
|
chinese="https://api-takumi.mihoyo.com/event/e20200928calculate/v1/",
|
||||||
)
|
)
|
||||||
|
|
||||||
DETAIL_LEDGER_URL = InternationalRoute(
|
DETAIL_LEDGER_URL = GameRoute(
|
||||||
overseas="https://sg-hk4e-api.hoyolab.com/event/ysledgeros/month_detail",
|
overseas=dict(
|
||||||
chinese="https://hk4e-api.mihoyo.com/event/ys_ledger/monthDetail",
|
genshin="https://sg-hk4e-api.hoyolab.com/event/ysledgeros/month_detail",
|
||||||
|
hkrpg="",
|
||||||
|
),
|
||||||
|
chinese=dict(
|
||||||
|
genshin="https://hk4e-api.mihoyo.com/event/ys_ledger/monthDetail",
|
||||||
|
hkrpg="https://api-takumi.mihoyo.com/event/srledger/month_detail",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
INFO_LEDGER_URL = GameRoute(
|
INFO_LEDGER_URL = GameRoute(
|
||||||
|
@ -36,6 +36,7 @@ class BadRequest(ApiHelperException):
|
|||||||
) -> None:
|
) -> None:
|
||||||
if status_code is not None:
|
if status_code is not None:
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
|
if response is not None:
|
||||||
ret_code = response.get("ret_code")
|
ret_code = response.get("ret_code")
|
||||||
if ret_code is not None:
|
if ret_code is not None:
|
||||||
self.ret_code = ret_code
|
self.ret_code = ret_code
|
||||||
|
Loading…
Reference in New Issue
Block a user