From da4ad8cb7158354a3f861cfa4917d8ddff923585 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Wed, 18 Mar 2026 20:10:13 +0000 Subject: [PATCH] improves error message when drive api not enabled for auth project --- app/shared/utils/sheets.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/shared/utils/sheets.py b/app/shared/utils/sheets.py index d2b23a9..c04f610 100644 --- a/app/shared/utils/sheets.py +++ b/app/shared/utils/sheets.py @@ -80,6 +80,18 @@ def check_sheet_write_access( if resp.status_code == 404: return False if resp.status_code == 403: + # Distinguish "API not enabled" from "no access to sheet" + try: + error_details = resp.json().get("error", {}) + for detail in error_details.get("details", []): + if detail.get("reason") == "SERVICE_DISABLED": + logger.warning( + f"Google Drive API is not enabled for this project." + f"Contact an admin to enable it at: {detail.get('metadata', {}).get('activationUrl', 'N/A')}" + ) + return None + except Exception: + pass return False if resp.status_code == 200: return resp.json().get("capabilities", {}).get("canEdit", False)