Improved logging
This commit is contained in:
@@ -20,7 +20,7 @@ from classes.exceptions import (
|
||||
UserCreationError,
|
||||
)
|
||||
from modules.logger import logWrite
|
||||
from modules.utils import configGet
|
||||
from modules.utils import configGet, locale
|
||||
|
||||
http_session = ClientSession(
|
||||
json_serialize=dumps,
|
||||
@@ -52,7 +52,15 @@ async def authorize() -> str:
|
||||
)
|
||||
if not response.ok:
|
||||
logWrite(
|
||||
f'Incorrect API credentials! Could not login into "{configGet("address", "posting", "api")}" using login "{configGet("username", "posting", "api")}": HTTP {response.status}'
|
||||
locale(
|
||||
"api_creds_invalid",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
configGet("address", "posting", "api"),
|
||||
configGet("username", "posting", "api"),
|
||||
response.status,
|
||||
),
|
||||
)
|
||||
)
|
||||
raise ValueError
|
||||
async with aiofiles.open(
|
||||
@@ -78,13 +86,34 @@ async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]:
|
||||
f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size={configGet("page_size", "posting")}&caption=queue',
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
logWrite("Random pic response: " + str(await resp.json()), debug=True)
|
||||
logWrite(
|
||||
locale("random_pic_response", "console", locale=configGet("locale_log")).format(
|
||||
await resp.json()
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
if resp.status != 200:
|
||||
logWrite(
|
||||
f'Could not get photos from album {configGet("album", "posting", "api")}: HTTP {resp.status}'
|
||||
locale(
|
||||
"random_pic_error_code",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
configGet("album", "posting", "api"), resp.status
|
||||
),
|
||||
),
|
||||
)
|
||||
logWrite(
|
||||
f'Could not get photos from "{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size={configGet("page_size", "posting")}&caption=queue" using token "{token}": HTTP {resp.status}',
|
||||
locale(
|
||||
"random_pic_error_debug",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
configGet("address", "posting", "api"),
|
||||
configGet("album", "posting", "api"),
|
||||
configGet("page_size", "posting"),
|
||||
token,
|
||||
resp.status,
|
||||
),
|
||||
),
|
||||
debug=True,
|
||||
)
|
||||
raise ValueError
|
||||
@@ -120,7 +149,13 @@ async def upload_pic(
|
||||
response_json = await response.json()
|
||||
if response.status != 200 and response.status != 409:
|
||||
logWrite(
|
||||
f"Could not upload '{filepath}' to API: HTTP {response.status} with message '{response.content}'"
|
||||
locale(
|
||||
"pic_upload_error",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(
|
||||
filepath, response.status, response.content
|
||||
),
|
||||
),
|
||||
)
|
||||
raise SubmissionUploadError(
|
||||
str(filepath), response.status, response.content
|
||||
@@ -161,7 +196,11 @@ async def find_pic(
|
||||
return (await response.json())["results"]
|
||||
except Exception as exp:
|
||||
logWrite(
|
||||
f"Could not find image with name '{name}' and caption '{caption}' due to: {exp}"
|
||||
locale(
|
||||
"find_pic_error",
|
||||
"console",
|
||||
locale=configGet("locale_log").format(name, caption, exp),
|
||||
),
|
||||
)
|
||||
return None
|
||||
|
||||
|
Reference in New Issue
Block a user