Skip to content

Commit e2d4864

Browse files
committed
Handle
1 parent 10b8a7c commit e2d4864

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

openhexa/cli/api.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
from datetime import datetime
1212
from importlib.metadata import version
1313
from pathlib import Path
14+
from typing import Any
1415
from zipfile import ZipFile
1516

1617
import click
1718
import docker
19+
import httpx
1820
import requests
1921
from docker.models.containers import Container
2022
from graphql import build_client_schema, build_schema, get_introspection_query
@@ -760,6 +762,9 @@ def execute(self, query, **kwargs):
760762
"""Decorate parent execute method to log the GraphQL query and response."""
761763
_detect_graphql_breaking_changes(token=self.token)
762764

765+
if self.token is None:
766+
raise InvalidTokenError("No token found for workspace")
767+
763768
if settings.debug:
764769
click.echo("")
765770
click.echo("Graphql Query:")
@@ -768,16 +773,21 @@ def execute(self, query, **kwargs):
768773
variables = kwargs.get("variables", {})
769774
click.echo(f"Variables: {variables}")
770775

771-
try:
772-
response = super().execute(query=query, **kwargs)
773-
except Exception as e:
774-
if "authenticated user" in str(e) or "UNAUTHENTICATED" in str(e):
775-
raise InvalidTokenError("No or invalid token found for workspace, the requests are not authenticated.")
776-
raise
776+
response = super().execute(query=query, **kwargs)
777777

778778
if settings.debug:
779779
click.echo("")
780780
click.echo("Graphql Response:")
781781
click.echo(f"Response: {response}")
782782

783783
return response
784+
785+
def get_data(self, response: httpx.Response) -> dict[str, Any]:
786+
"""Get the data from the response, handling errors and authentication issues."""
787+
try:
788+
data = super().get_data(response)
789+
except Exception as e:
790+
if "Resolver requires an authenticated user" in str(e):
791+
raise InvalidTokenError("No or invalid token found for workspace, please check your configuration.")
792+
raise
793+
return data

0 commit comments

Comments
 (0)