1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Exceptions classes redesign followup

This commit is contained in:
Mr. Dog 2020-08-03 06:39:12 +05:00 committed by GitHub
parent e987e40ee7
commit c17a2379ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,7 +105,10 @@ def _make_request(token, method_name, method='get', params=None, files=None):
timeout=(connect_timeout, read_timeout), proxies=proxy) timeout=(connect_timeout, read_timeout), proxies=proxy)
logger.debug("The server returned: '{0}'".format(result.text.encode('utf8'))) logger.debug("The server returned: '{0}'".format(result.text.encode('utf8')))
return _check_result(method_name, result)['result']
json_result = _check_result(method_name, result)
if json_result:
return json_result['result']
def _check_result(method_name, result): def _check_result(method_name, result):
@ -121,16 +124,16 @@ def _check_result(method_name, result):
:param result: The returned result of the method request :param result: The returned result of the method request
:return: The result parsed to a JSON dictionary. :return: The result parsed to a JSON dictionary.
""" """
if result.status_code != 200:
raise ApiHTTPException(method_name, result)
try: try:
result_json = result.json() result_json = result.json()
except: except:
raise ApiInvalidJSONException(method_name, result) raise ApiInvalidJSONException(method_name, result)
else:
if not result_json['ok']: if not result_json['ok']:
raise ApiTelegramException(msg, method_name, result, result_json) raise ApiTelegramException(method_name, result, result_json)
elif result.status_code != 200:
raise ApiHTTPException(method_name, result)
return result_json return result_json
@ -1291,4 +1294,5 @@ class ApiTelegramException(ApiException):
function_name, function_name,
result) result)
self.result_json = result_json self.result_json = result_json
self.error_code = result_json['error_code']