Skip to content

Commit 3111158

Browse files
authored
Added info logging for response (#511)
* Added some logging support * Logs are based on what the server returns * Added back some of the better errors * Print status if not detected as error * Added logging in the flush step * Reformatted * Removed some unnecessary
1 parent ce456fa commit 3111158

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/databricks/sql/auth/retry.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -345,23 +345,24 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
345345
if a retry would violate the configured policy.
346346
"""
347347

348+
logger.info(f"Received status code {status_code} for {method} request")
349+
348350
# Request succeeded. Don't retry.
349351
if status_code == 200:
350352
return False, "200 codes are not retried"
351353

352354
if status_code == 401:
353-
raise NonRecoverableNetworkError(
354-
"Received 401 - UNAUTHORIZED. Confirm your authentication credentials."
355+
return (
356+
False,
357+
"Received 401 - UNAUTHORIZED. Confirm your authentication credentials.",
355358
)
356359

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

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

366367
# Request failed and this method is not retryable. We only retry POST requests.
367368
if not self._is_method_retryable(method):
@@ -400,8 +401,9 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
400401
and status_code not in self.status_forcelist
401402
and status_code not in self.force_dangerous_codes
402403
):
403-
raise UnsafeToRetryError(
404-
"ExecuteStatement command can only be retried for codes 429 and 503"
404+
return (
405+
False,
406+
"ExecuteStatement command can only be retried for codes 429 and 503",
405407
)
406408

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

src/databricks/sql/auth/thrift_http_client.py

+6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ def flush(self):
198198
self.message = self.__resp.reason
199199
self.headers = self.__resp.headers
200200

201+
logger.info(
202+
"HTTP Response with status code {}, message: {}".format(
203+
self.code, self.message
204+
)
205+
)
206+
201207
@staticmethod
202208
def basic_proxy_auth_headers(proxy):
203209
if proxy is None or not proxy.username:

0 commit comments

Comments
 (0)