mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-23 06:50:29 +01:00
Try to process response data after checking errors, not before. Add 413 File too large http error message.
This commit is contained in:
parent
3863b4f371
commit
6ffd75e421
1 changed files with 7 additions and 5 deletions
|
@ -183,22 +183,24 @@ class Request(object):
|
|||
# 200-299 range are HTTP success statuses
|
||||
return resp.data
|
||||
|
||||
try:
|
||||
message = self._parse(resp.data)
|
||||
except ValueError:
|
||||
raise NetworkError('Unknown HTTPError {0}'.format(resp.status))
|
||||
|
||||
if resp.status in (401, 403):
|
||||
raise Unauthorized(message)
|
||||
elif resp.status == 400:
|
||||
raise BadRequest(message)
|
||||
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')
|
||||
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…
Reference in a new issue