add InvalidUidError

This commit is contained in:
baiqwerdvd 2024-03-06 20:46:35 +08:00
parent 624236672e
commit fae0b02574
No known key found for this signature in database
GPG Key ID: 7378121720ECEBED
2 changed files with 14 additions and 1 deletions

View File

@ -8,6 +8,13 @@ class UidNotfoundError(Exception):
def __str__(self):
return self.uid
class InvalidUidError(Exception):
def __init__(self, uid: str):
self.uid = uid
def __str__(self):
return self.uid
class CharNameError(Exception):
def __init__(self, char_name: str):

View File

@ -7,7 +7,11 @@ import msgspec
from httpx import AsyncClient
from msgspec import convert
from starrail_damage_cal.exception import MihomoModelError, MihomoQueueTimeoutError
from starrail_damage_cal.exception import (
InvalidUidError,
MihomoModelError,
MihomoQueueTimeoutError,
)
from starrail_damage_cal.mihomo.models import MihomoData
_HEADER = {"User-Agent": "StarRailDamageCal/"}
@ -33,6 +37,8 @@ async def get_char_card_info(
except msgspec.ValidationError as e:
if req.text == '{"detail":"Queue timeout"}':
raise MihomoQueueTimeoutError from e
if req.text == '{"detail":"Invalid uid"}':
raise InvalidUidError(uid) from e
raise MihomoModelError(e) from e
except json.decoder.JSONDecodeError as e:
raise MihomoModelError(e) from e