Commit 54ebfd8b47bdca8b147169025ded01a21bba6518

Authored by Yurii Mykhalchuk
Committed by GitHub
2 parents 3bb45ee4 28c5770b

Merge pull request #282 from mykhaly/devel

Rewrite `retry_if_request_failed`
1 1 from openprocurement_client.client import Client
2 2 from openprocurement_client.utils import get_tender_id_by_uaid
3 3 from openprocurement_client.exceptions import IdNotFound
4   -from restkit.errors import RequestFailed
  4 +from restkit.errors import RequestFailed, BadStatusLine
5 5 from retrying import retry
6 6 import os
7 7 import urllib
8 8
9 9
10 10 def retry_if_request_failed(exception):
11   - return isinstance(exception, RequestFailed)
  11 + if isinstance(exception, RequestFailed):
  12 + status_code = getattr(exception, 'status_int', None)
  13 + if 500 <= status_code < 600 or status_code == 429:
  14 + return True
  15 + else:
  16 + return False
  17 + else:
  18 + return isinstance(exception, BadStatusLine)
12 19
13 20
14 21 class StableClient(Client):
... ...
Please register or login to post a comment