Skip to content

Wrap all requests.exceptions.RequestException as TrinoConnectionError #393

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

Merged
Show file tree
Hide file tree
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 trino/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,10 @@ def execute(self, additional_http_headers=None) -> TrinoResult:
if self.cancelled:
raise exceptions.TrinoUserError("Query has been cancelled", self.query_id)

response = self._request.post(self._query, additional_http_headers)
try:
response = self._request.post(self._query, additional_http_headers)
except requests.exceptions.RequestException as e:
raise trino.exceptions.TrinoConnectionError("failed to execute: {}".format(e))
Copy link
Contributor

@mdesmet mdesmet Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a OperationalError is more at its place here.

This also applies to the other places where you wrap this exception, otherwise it would not be captured by other frameworks like sqlalchemy.

status = self._request.process(response)
self._info_uri = status.info_uri
self._query_id = status.id
Expand Down Expand Up @@ -834,7 +837,10 @@ def _update_state(self, status):

def fetch(self) -> List[List[Any]]:
"""Continue fetching data for the current query_id"""
response = self._request.get(self._request.next_uri)
try:
response = self._request.get(self._request.next_uri)
except requests.exceptions.RequestException as e:
raise trino.exceptions.TrinoConnectionError("failed to fetch: {}".format(e))
status = self._request.process(response)
self._update_state(status)
logger.debug(status)
Expand All @@ -852,7 +858,10 @@ def cancel(self) -> None:
return

logger.debug("cancelling query: %s", self.query_id)
response = self._request.delete(self._next_uri)
try:
response = self._request.delete(self._next_uri)
except requests.exceptions.RequestException as e:
raise trino.exceptions.TrinoConnectionError("failed to cancel query: {}".format(e))
logger.debug(response)
if response.status_code == requests.codes.no_content:
self._cancelled = True
Expand Down
4 changes: 4 additions & 0 deletions trino/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class TrinoAuthError(OperationalError):
pass


class TrinoConnectionError(OperationalError):
pass


class TrinoDataError(NotSupportedError):
pass

Expand Down