Try to process response data after checking errors, not before. Add 413 File too large http error message.

This commit is contained in:
Alateas 2017-06-15 18:44:39 +03:00
parent 3863b4f371
commit 6ffd75e421

View file

@ -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.