Changed the way exceptions are handled

This commit is contained in:
Profitroll
2023-02-17 16:45:51 +01:00
parent 663a7b0db8
commit 07203a9db9
4 changed files with 46 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ from random import choice
from typing import Tuple, Union
from requests import get, patch, post
from classes.exceptions import SubmissionUploadError
from modules.logger import logWrite
from modules.utils import configGet
@@ -59,7 +60,7 @@ async def upload_pic(filepath: str, token: Union[str, None] = None) -> Tuple[boo
response = post(f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos', params={"caption": "queue", "compress": False}, headers={"Authorization": f"Bearer {token}"}, files=files)
if response.status_code != 200 and response.status_code != 409:
logWrite(f"Could not upload '{filepath}' to API: HTTP {response.status_code} with message '{response.content}'")
return False, []
raise SubmissionUploadError(str(filepath), response.status_code, response.content)
duplicates = []
if "duplicates" in response.json():
for duplicate in response.json()["duplicates"]:

View File

@@ -1,4 +1,4 @@
from pyrogram.client import Client
from modules.utils import configGet
from classes.poster_client import PosterClient
app = Client("duptsiaposter", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
app = PosterClient("duptsiaposter", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))