Skip to content

Commit

Permalink
Retry 500 status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
aniezurawski authored May 14, 2021
1 parent 113c08c commit 2987005
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions neptune/new/internal/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

from bravado.client import SwaggerClient
from bravado.exception import BravadoConnectionError, BravadoTimeoutError, HTTPForbidden, \
HTTPInternalServerError, HTTPServerError, HTTPUnauthorized, HTTPServiceUnavailable, HTTPRequestTimeout, \
HTTPServerError, HTTPUnauthorized, HTTPServiceUnavailable, HTTPRequestTimeout, \
HTTPGatewayTimeout, HTTPBadGateway, HTTPClientError, HTTPTooManyRequests
from bravado.http_client import HttpClient
from bravado_core.formatter import SwaggerFormat
from packaging.version import Version
from requests import Session

from neptune.new.exceptions import SSLError, NeptuneConnectionLostException, InternalServerError, \
from neptune.new.exceptions import SSLError, NeptuneConnectionLostException, \
Unauthorized, Forbidden, CannotResolveHostname, UnsupportedClientVersion, ClientHttpError
from neptune.new.internal.backends.api_model import ClientConfig
from neptune.new.internal.utils import replace_patch_version
Expand All @@ -54,12 +54,10 @@ def wrapper(*args, **kwargs):
except (BravadoConnectionError, BravadoTimeoutError,
requests.exceptions.ConnectionError, requests.exceptions.Timeout,
HTTPRequestTimeout, HTTPServiceUnavailable, HTTPGatewayTimeout, HTTPBadGateway,
HTTPTooManyRequests) as e:
HTTPTooManyRequests, HTTPServerError) as e:
time.sleep(2 ** retry)
last_exception = e
continue
except HTTPServerError as e:
raise InternalServerError(e.response.text) from e
except HTTPUnauthorized:
raise Unauthorized()
except HTTPForbidden:
Expand All @@ -75,12 +73,11 @@ def wrapper(*args, **kwargs):
HTTPBadGateway.status_code,
HTTPServiceUnavailable.status_code,
HTTPGatewayTimeout.status_code,
HTTPTooManyRequests.status_code):
HTTPTooManyRequests.status_code,
HTTPServerError.status_code):
time.sleep(2 ** retry)
last_exception = e
continue
elif status_code >= HTTPInternalServerError.status_code:
raise InternalServerError(e.response.text) from e
elif status_code == HTTPUnauthorized.status_code:
raise Unauthorized()
elif status_code == HTTPForbidden.status_code:
Expand Down

0 comments on commit 2987005

Please sign in to comment.