Skip to content

Commit 6ffd75e

Browse files
Try to process response data after checking errors, not before. Add 413 File too large http error message.
1 parent 3863b4f commit 6ffd75e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

telegram/utils/request.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,24 @@ def _request_wrapper(self, *args, **kwargs):
183183
# 200-299 range are HTTP success statuses
184184
return resp.data
185185

186-
try:
187-
message = self._parse(resp.data)
188-
except ValueError:
189-
raise NetworkError('Unknown HTTPError {0}'.format(resp.status))
190-
191186
if resp.status in (401, 403):
192187
raise Unauthorized(message)
193188
elif resp.status == 400:
194189
raise BadRequest(message)
195190
elif resp.status == 404:
196191
raise InvalidToken()
192+
elif resp.status == 413:
193+
raise NetworkError('File too large. Check telegram api limits https://core.telegram.org/bots/api#senddocument')
197194
elif resp.status == 502:
198195
raise NetworkError('Bad Gateway')
199196
else:
200197
raise NetworkError('{0} ({1})'.format(message, resp.status))
201198

199+
try:
200+
message = self._parse(resp.data)
201+
except ValueError:
202+
raise NetworkError('Unknown HTTPError {0}'.format(resp.status))
203+
202204
def get(self, url, timeout=None):
203205
"""Request an URL.
204206

0 commit comments

Comments
 (0)