Commit 28c5770b8a9b15e5fbe5e97cfa19fb6ba46bc9e9

Authored by mykhaly
1 parent 3bb45ee4

Rewrite `retry_if_request_failed`

Retry only requests with 5xx and 429 status codes or requests which throw BadStatusLine exception.
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