1111from datetime import datetime
1212from importlib .metadata import version
1313from pathlib import Path
14+ from typing import Any
1415from zipfile import ZipFile
1516
1617import click
1718import docker
19+ import httpx
1820import requests
1921from docker .models .containers import Container
2022from 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