mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-30 11:19:24 +02:00
Properly try to parse server message before raising errors
This commit is contained in:
parent
6ffd75e421
commit
7a89dcb911
1 changed files with 8 additions and 6 deletions
|
@ -183,6 +183,11 @@ class Request(object):
|
|||
# 200-299 range are HTTP success statuses
|
||||
return resp.data
|
||||
|
||||
try:
|
||||
message = self._parse(resp.data)
|
||||
except ValueError:
|
||||
message = 'Unknown HTTPError'
|
||||
|
||||
if resp.status in (401, 403):
|
||||
raise Unauthorized(message)
|
||||
elif resp.status == 400:
|
||||
|
@ -190,17 +195,14 @@ class Request(object):
|
|||
elif resp.status == 404:
|
||||
raise InvalidToken()
|
||||
elif resp.status == 413:
|
||||
raise NetworkError('File too large. Check telegram api limits https://core.telegram.org/bots/api#senddocument')
|
||||
raise NetworkError('File too large. Check telegram api limits '
|
||||
'https://core.telegram.org/bots/api#senddocument')
|
||||
|
||||
elif resp.status == 502:
|
||||
raise NetworkError('Bad Gateway')
|
||||
else:
|
||||
raise NetworkError('{0} ({1})'.format(message, resp.status))
|
||||
|
||||
try:
|
||||
message = self._parse(resp.data)
|
||||
except ValueError:
|
||||
raise NetworkError('Unknown HTTPError {0}'.format(resp.status))
|
||||
|
||||
def get(self, url, timeout=None):
|
||||
"""Request an URL.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue