Skip to content

Commit

Permalink
fix: add try catch arround response.json() for catch error on export
Browse files Browse the repository at this point in the history
  • Loading branch information
FannyGaudin committed Jul 29, 2024
1 parent 691a625 commit 1bef9f3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/kili/core/graphql/graphql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from urllib.parse import urlparse

import graphql
import requests
from filelock import FileLock
from gql import Client, gql
from gql.transport import exceptions
Expand Down Expand Up @@ -115,6 +116,9 @@ def __init__(
)

self._gql_client = self._initizalize_graphql_client()
logging.basicConfig()
self.logger = logging.getLogger(__name__)
self.logger.setLevel(logging.WARNING)

def _get_headers(self) -> Dict[str, str]:
"""Get the headers."""
Expand Down Expand Up @@ -224,6 +228,12 @@ def _get_kili_app_version(self) -> Optional[str]:
"""
url = self.endpoint.replace("/graphql", "/version")
response = self.http_client.get(url, timeout=30)
try:
response.raise_for_status()
except requests.exceptions.HTTPError as err:
self.logger.warning("An error occurred while processing the response: %s", err)
raise RuntimeError(f"An error occurred while processing the response: {err}") from err

if response.status_code == 200 and '"version":' in response.text:
response_json = response.json()
return response_json["version"]
Expand Down

0 comments on commit 1bef9f3

Please sign in to comment.