apply ruff formatting
This commit is contained in:
@@ -27,6 +27,7 @@ class UserInputError(Exception):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def check_credentials_directory_permissions(credentials_dir: str = None) -> None:
|
||||
"""
|
||||
Check if the service has appropriate permissions to create and write to the .credentials directory.
|
||||
@@ -181,7 +182,7 @@ def extract_office_xml_text(file_bytes: bytes, mime_type: str) -> Optional[str]:
|
||||
member_texts.append(shared_strings[ss_idx])
|
||||
else:
|
||||
logger.warning(
|
||||
f"Invalid shared string index {ss_idx} in {member}. Max index: {len(shared_strings)-1}"
|
||||
f"Invalid shared string index {ss_idx} in {member}. Max index: {len(shared_strings) - 1}"
|
||||
)
|
||||
except ValueError:
|
||||
logger.warning(
|
||||
@@ -240,7 +241,9 @@ def extract_office_xml_text(file_bytes: bytes, mime_type: str) -> Optional[str]:
|
||||
return None
|
||||
|
||||
|
||||
def handle_http_errors(tool_name: str, is_read_only: bool = False, service_type: Optional[str] = None):
|
||||
def handle_http_errors(
|
||||
tool_name: str, is_read_only: bool = False, service_type: Optional[str] = None
|
||||
):
|
||||
"""
|
||||
A decorator to handle Google API HttpErrors and transient SSL errors in a standardized way.
|
||||
|
||||
@@ -288,11 +291,16 @@ def handle_http_errors(tool_name: str, is_read_only: bool = False, service_type:
|
||||
except HttpError as error:
|
||||
user_google_email = kwargs.get("user_google_email", "N/A")
|
||||
error_details = str(error)
|
||||
|
||||
|
||||
# Check if this is an API not enabled error
|
||||
if error.resp.status == 403 and "accessNotConfigured" in error_details:
|
||||
enablement_msg = get_api_enablement_message(error_details, service_type)
|
||||
|
||||
if (
|
||||
error.resp.status == 403
|
||||
and "accessNotConfigured" in error_details
|
||||
):
|
||||
enablement_msg = get_api_enablement_message(
|
||||
error_details, service_type
|
||||
)
|
||||
|
||||
if enablement_msg:
|
||||
message = (
|
||||
f"API error in {tool_name}: {enablement_msg}\n\n"
|
||||
@@ -314,7 +322,7 @@ def handle_http_errors(tool_name: str, is_read_only: bool = False, service_type:
|
||||
else:
|
||||
# Other HTTP errors (400 Bad Request, etc.) - don't suggest re-auth
|
||||
message = f"API error in {tool_name}: {error}"
|
||||
|
||||
|
||||
logger.error(f"API error in {tool_name}: {error}", exc_info=True)
|
||||
raise Exception(message) from error
|
||||
except TransientNetworkError:
|
||||
|
||||
Reference in New Issue
Block a user