mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added more details when server send invalid response
This commit is contained in:
parent
44ae565149
commit
efae83d337
4 changed files with 56 additions and 3 deletions
|
|
@ -7,7 +7,10 @@ from http import HTTPStatus
|
|||
from types import TracebackType
|
||||
from typing import TYPE_CHECKING, Any, AsyncGenerator, Callable, Final, Optional, Type, Union, cast
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from aiogram.exceptions import (
|
||||
ClientDecodeError,
|
||||
RestartingTelegram,
|
||||
TelegramAPIError,
|
||||
TelegramBadRequest,
|
||||
|
|
@ -64,8 +67,19 @@ class BaseSession(abc.ABC):
|
|||
"""
|
||||
Check response status
|
||||
"""
|
||||
json_data = self.json_loads(content)
|
||||
response = method.build_response(json_data)
|
||||
try:
|
||||
json_data = self.json_loads(content)
|
||||
except Exception as e:
|
||||
# Handled error type can't be classified as specific error
|
||||
# in due to decoder can be customized and raise any exception
|
||||
|
||||
raise ClientDecodeError("Failed to decode object", e, content)
|
||||
|
||||
try:
|
||||
response = method.build_response(json_data)
|
||||
except ValidationError as e:
|
||||
raise ClientDecodeError("Failed to deserialize object", e, json_data)
|
||||
|
||||
if HTTPStatus.OK <= status_code <= HTTPStatus.IM_USED and response.ok:
|
||||
return response
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue