feat: add models and partially custom error messages
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user