mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #935 from mrpes/patch-4
Exceptions classes redesign followup
This commit is contained in:
commit
dc07cacc7f
@ -104,7 +104,10 @@ def _make_request(token, method_name, method='get', params=None, files=None):
|
||||
timeout=(connect_timeout, read_timeout), proxies=proxy)
|
||||
|
||||
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):
|
||||
@ -120,14 +123,14 @@ def _check_result(method_name, result):
|
||||
:param result: The returned result of the method request
|
||||
:return: The result parsed to a JSON dictionary.
|
||||
"""
|
||||
if result.status_code != 200:
|
||||
raise ApiHTTPException(method_name, result)
|
||||
|
||||
try:
|
||||
result_json = result.json()
|
||||
except:
|
||||
if result.status_code != 200:
|
||||
raise ApiHTTPException(method_name, result)
|
||||
else:
|
||||
raise ApiInvalidJSONException(method_name, result)
|
||||
|
||||
else:
|
||||
if not result_json['ok']:
|
||||
raise ApiTelegramException(method_name, result, result_json)
|
||||
|
||||
@ -1290,4 +1293,5 @@ class ApiTelegramException(ApiException):
|
||||
function_name,
|
||||
result)
|
||||
self.result_json = result_json
|
||||
self.error_code = result_json['error_code']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user