Skip to content

Commit 9944f78

Browse files
committed
Logs are based on what the server returns
1 parent 0a559ee commit 9944f78

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/databricks/sql/auth/retry.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,17 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
352352
return False, "200 codes are not retried"
353353

354354
if status_code == 401:
355-
raise NonRecoverableNetworkError(
356-
"Received 401 - UNAUTHORIZED. Confirm your authentication credentials."
355+
return (
356+
False,
357+
"Received 401 - UNAUTHORIZED. Confirm your authentication credentials.",
357358
)
358359

359360
if status_code == 403:
360-
raise NonRecoverableNetworkError(
361-
"Received 403 - FORBIDDEN. Confirm your authentication credentials."
362-
)
361+
return False, "403 codes are not retried"
363362

364363
# Request failed and server said NotImplemented. This isn't recoverable. Don't retry.
365364
if status_code == 501:
366-
raise NonRecoverableNetworkError("Received code 501 from server.")
365+
return False, "Received code 501 from server."
367366

368367
# Request failed and this method is not retryable. We only retry POST requests.
369368
if not self._is_method_retryable(method):
@@ -382,8 +381,9 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
382381
and self.command_type == CommandType.CLOSE_SESSION
383382
and len(self.history) > 0
384383
):
385-
raise SessionAlreadyClosedError(
386-
"CloseSession received 404 code from Databricks. Session is already closed."
384+
return (
385+
False,
386+
"CloseSession received 404 code from Databricks. Session is already closed.",
387387
)
388388

389389
# Request failed with 404 because CloseOperation returns 404 if you repeat the request.
@@ -392,8 +392,9 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
392392
and self.command_type == CommandType.CLOSE_OPERATION
393393
and len(self.history) > 0
394394
):
395-
raise CursorAlreadyClosedError(
396-
"CloseOperation received 404 code from Databricks. Cursor is already closed."
395+
return (
396+
False,
397+
"CloseOperation received 404 code from Databricks. Cursor is already closed.",
397398
)
398399

399400
# Request failed, was an ExecuteStatement and the command may have reached the server
@@ -402,8 +403,9 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
402403
and status_code not in self.status_forcelist
403404
and status_code not in self.force_dangerous_codes
404405
):
405-
raise UnsafeToRetryError(
406-
"ExecuteStatement command can only be retried for codes 429 and 503"
406+
return (
407+
False,
408+
"ExecuteStatement command can only be retried for codes 429 and 503",
407409
)
408410

409411
# Request failed with a dangerous code, was an ExecuteStatement, but user forced retries for this

0 commit comments

Comments
 (0)