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.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.ds import generate_dynamic_secret, DSType, hex_digest
|
||||
from simnet.utils.enum_ import Region, Game
|
||||
@ -308,6 +308,8 @@ class BaseClient(AsyncContextManager["BaseClient"]):
|
||||
if response.is_error or ret_code != 0:
|
||||
raise_for_ret_code(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)
|
||||
|
||||
async def request_lab(
|
||||
|
@ -44,7 +44,7 @@ class BaseDiaryClient(BaseClient):
|
||||
params = params or {}
|
||||
|
||||
url = (
|
||||
DETAIL_LEDGER_URL.get_url(self.region)
|
||||
DETAIL_LEDGER_URL.get_url(self.region, game)
|
||||
if detail
|
||||
else INFO_LEDGER_URL.get_url(
|
||||
self.region,
|
||||
|
@ -61,6 +61,15 @@ class 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:
|
||||
"""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/",
|
||||
)
|
||||
|
||||
DETAIL_LEDGER_URL = InternationalRoute(
|
||||
overseas="https://sg-hk4e-api.hoyolab.com/event/ysledgeros/month_detail",
|
||||
chinese="https://hk4e-api.mihoyo.com/event/ys_ledger/monthDetail",
|
||||
DETAIL_LEDGER_URL = GameRoute(
|
||||
overseas=dict(
|
||||
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(
|
||||
|
@ -36,6 +36,7 @@ class BadRequest(ApiHelperException):
|
||||
) -> None:
|
||||
if status_code is not None:
|
||||
self.status_code = status_code
|
||||
if response is not None:
|
||||
ret_code = response.get("ret_code")
|
||||
if ret_code is not None:
|
||||
self.ret_code = ret_code
|
||||
|
Loading…
Reference in New Issue
Block a user