From 620b126248fcd64759f838faa22b58db61985130 Mon Sep 17 00:00:00 2001 From: Piotr Kasprzyk <14312755+pkasprzyk@users.noreply.github.com> Date: Thu, 20 Jan 2022 18:18:36 +0100 Subject: [PATCH] retry 408 and 429 statuses in legacy client (#829) * retry 408 and 429 statuses in legacy client * changelog * more consistency in catching exceptions * fix duplicate handling --- CHANGELOG.md | 1 + neptune/utils.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d04e8e0ae..ce2356d8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## Fixes - Raise proper exception when invalid token were provided ([#825](https://github.com/neptune-ai/neptune-client/pull/825)) +- Make status error-handling in legacy client consistent with neptune.new ([#829](https://github.com/neptune-ai/neptune-client/pull/829)) ## neptune-client 0.14.2 diff --git a/neptune/utils.py b/neptune/utils.py index 0707b70d8..ba5b85717 100644 --- a/neptune/utils.py +++ b/neptune/utils.py @@ -42,7 +42,9 @@ HTTPServerError, HTTPServiceUnavailable, HTTPUnauthorized, + HTTPTooManyRequests, ) +from urllib3.exceptions import NewConnectionError from neptune import envs from neptune.api_exceptions import ( @@ -324,6 +326,9 @@ def wrapper(*args, **kwargs): HTTPRequestTimeout, HTTPGatewayTimeout, HTTPBadGateway, + HTTPTooManyRequests, + HTTPServerError, + NewConnectionError, ): if retry >= 6: _logger.warning( @@ -332,8 +337,6 @@ def wrapper(*args, **kwargs): time.sleep(2 ** retry) retry += 1 continue - except HTTPServerError: - raise ServerError() except HTTPUnauthorized: raise Unauthorized() except HTTPForbidden: @@ -357,9 +360,12 @@ def wrapper(*args, **kwargs): time.sleep(2 ** retry) continue elif status_code in ( + HTTPRequestTimeout.status_code, HTTPBadGateway.status_code, HTTPServiceUnavailable.status_code, HTTPGatewayTimeout.status_code, + HTTPTooManyRequests.status_code, + HTTPServerError.status_code, ): if retry >= 6: _logger.warning(