feat: add models and partially custom error messages

This commit is contained in:
firedotguy
2026-01-31 12:10:20 +03:00
parent c7e3812ee8
commit a388426d8d
15 changed files with 352 additions and 71 deletions

View File

@@ -2,6 +2,8 @@ from _io import BufferedReader
from requests import Session
from itd.exceptions import InvalidToken, InvalidCookie
s = Session()
@@ -29,8 +31,9 @@ def fetch(token: str, method: str, url: str, params: dict = {}, files: dict[str,
else:
res = s.request(method.upper(), base, timeout=20, json=params, headers=headers, files=files)
res.raise_for_status()
return res.json()
print(res.text)
return res
def set_cookies(cookies: str):
for cookie in cookies.split('; '):
@@ -65,5 +68,11 @@ def auth_fetch(cookies: str, method: str, url: str, params: dict = {}, token: st
res = s.get(f'https://xn--d1ah4a.com/api/{url}', timeout=20, params=params, headers=headers)
else:
res = s.request(method, f'https://xn--d1ah4a.com/api/{url}', timeout=20, json=params, headers=headers)
res.raise_for_status()
return res.json()
# print(res.text)
if res.text == 'UNAUTHORIZED':
raise InvalidToken()
if res.json().get('error', {}).get('code') in ('SESSION_NOT_FOUND', 'REFRESH_TOKEN_MISSING'):
raise InvalidCookie()
return res