Commit 54ebfd8b47bdca8b147169025ded01a21bba6518
Committed by
GitHub
Merge pull request #282 from mykhaly/devel
Rewrite `retry_if_request_failed`
Showing
1 changed file
with
9 additions
and
2 deletions
1 | from openprocurement_client.client import Client | 1 | from openprocurement_client.client import Client |
2 | from openprocurement_client.utils import get_tender_id_by_uaid | 2 | from openprocurement_client.utils import get_tender_id_by_uaid |
3 | from openprocurement_client.exceptions import IdNotFound | 3 | from openprocurement_client.exceptions import IdNotFound |
4 | -from restkit.errors import RequestFailed | 4 | +from restkit.errors import RequestFailed, BadStatusLine |
5 | from retrying import retry | 5 | from retrying import retry |
6 | import os | 6 | import os |
7 | import urllib | 7 | import urllib |
8 | 8 | ||
9 | 9 | ||
10 | def retry_if_request_failed(exception): | 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 | class StableClient(Client): | 21 | class StableClient(Client): |
Please
register
or
login
to post a comment