(self, response: httpx.Response)
| 840 | return timeout if timeout >= 0 else 0 |
| 841 | |
| 842 | def _should_retry(self, response: httpx.Response) -> bool: |
| 843 | # Note: this is not a standard header |
| 844 | should_retry_header = response.headers.get("x-should-retry") |
| 845 | |
| 846 | # If the server explicitly says whether or not to retry, obey. |
| 847 | if should_retry_header == "true": |
| 848 | log.debug("Retrying as header `x-should-retry` is set to `true`") |
| 849 | return True |
| 850 | if should_retry_header == "false": |
| 851 | log.debug("Not retrying as header `x-should-retry` is set to `false`") |
| 852 | return False |
| 853 | |
| 854 | # Retry on request timeouts. |
| 855 | if response.status_code == 408: |
| 856 | log.debug("Retrying due to status code %i", response.status_code) |
| 857 | return True |
| 858 | |
| 859 | # Retry on lock timeouts. |
| 860 | if response.status_code == 409: |
| 861 | log.debug("Retrying due to status code %i", response.status_code) |
| 862 | return True |
| 863 | |
| 864 | # Retry on rate limits. |
| 865 | if response.status_code == 429: |
| 866 | log.debug("Retrying due to status code %i", response.status_code) |
| 867 | return True |
| 868 | |
| 869 | # Retry internal errors. |
| 870 | if response.status_code >= 500: |
| 871 | log.debug("Retrying due to status code %i", response.status_code) |
| 872 | return True |
| 873 | |
| 874 | log.debug("Not retrying") |
| 875 | return False |
| 876 | |
| 877 | def _should_retry_exception(self, err: BaseException) -> tuple[bool, httpx.Response | None]: |
| 878 | """Whether an exception raised by a request attempt should be retried. |
no test coverage detected