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

Make Retry context manager not swallow exceptions #150

Merged
merged 1 commit into from
Sep 12, 2024
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
15 changes: 12 additions & 3 deletions tsdapiclient/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,18 @@ def __enter__(self) -> dict:
elif rc in [500, 504] or reconnect:
self.counter -= 1
retry_attempt_no += 1
debug_step(f'timeout: retrying request attempt {retry_attempt_no}/{total}')
debug_step(
f"timeout: retrying request attempt {retry_attempt_no}/{total}"
)
if self.counter == 0: # this was the last attempt
self.resp.raise_for_status()
else:
return {"resp": self.resp, "new_session": new_session}

def __exit__(self, type, value, traceback) -> dict:
return {"resp": self.resp, "new_session": None} # caller should raise from that
def __exit__(self, exc_type, exc_value, exc_traceback) -> dict:
if exc_type:
raise exc_type(exc_value).with_traceback(exc_traceback)
return {
"resp": self.resp,
"new_session": None,
}
Loading