Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sca): send exception log when exceeded retries #3534

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions checkov/common/util/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,24 @@ def request_wrapper(
return response
except requests.exceptions.ConnectionError as connection_error:
logging.error(f"Connection error on request {method}:{url},\ndata:\n{data}\njson:{json}\nheaders:{headers}")
logging.exception("request_wrapper connection error")
if i != request_max_tries - 1:
sleep_secs = sleep_between_request_tries * (i + 1)
logging.info(f"retrying attempt number {i + 2} in {sleep_secs} seconds")
time.sleep(sleep_secs)
continue

logging.exception("request_wrapper connection error")
raise connection_error
except requests.exceptions.HTTPError as http_error:
status_code = http_error.response.status_code
logging.error(f"HTTP error on request {method}:{url},\ndata:\n{data}\njson:{json}\nheaders:{headers}")
logging.exception("request_wrapper http error")
if (status_code >= 500 or status_code == 403) and i != request_max_tries - 1:
sleep_secs = sleep_between_request_tries * (i + 1)
logging.info(f"retrying attempt number {i + 2} in {sleep_secs} seconds")
time.sleep(sleep_secs)
continue

logging.exception("request_wrapper http error")
raise http_error
else:
raise Exception("Unexpected behavior: the method \'request_wrapper\' should be terminated inside the above for-"
Expand Down