From 46dc038e260846d50106d25f63cb5db861816fdd Mon Sep 17 00:00:00 2001 From: king Date: Wed, 7 Oct 2026 12:59:33 +0900 Subject: [PATCH] fix(project): show OAuth error code when meeting board token refresh fails RefreshError showed only a generic message; include Google's error code and explain client ID/secret mismatch (unauthorized_client). Co-Authored-By: Claude Opus 5.5 --- app/integrations/google_slides.py | 9 ++++++++- tests/test_project_meeting_board.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/integrations/google_slides.py b/app/integrations/google_slides.py index 211cde3..82c53c5 100644 --- a/app/integrations/google_slides.py +++ b/app/integrations/google_slides.py @@ -20,6 +20,7 @@ from __future__ import annotations import json import os +import re import threading from typing import Any @@ -153,6 +154,12 @@ def _friendly(exc: Exception) -> str: """Google API 오류 → 화면용 문구(비밀값·원문 응답 미포함).""" status = getattr(getattr(exc, "resp", None), "status", None) text = str(exc) + # 토큰 갱신 실패(RefreshError) — Google 이 준 OAuth 오류 코드(비밀값 아님)를 보여 원인을 바로 알 수 있게 + m = re.search(r"\b(invalid_scope|invalid_grant|invalid_client|unauthorized_client|deleted_client|access_denied|invalid_request)\b", text) + code = m.group(1) if m else "" + if code in ("unauthorized_client", "invalid_client", "deleted_client"): + return (f"Google 토큰 갱신 실패({code}) — 토큰을 발급한 OAuth 클라이언트와 서버 .env 의 " + "GOOGLE_SHEETS_OAUTH_CLIENT_ID/SECRET(없으면 GOOGLE_CLIENT_ID/SECRET)이 다릅니다.") if "invalid_scope" in text or "insufficient" in text.lower() or "ACCESS_TOKEN_SCOPE_INSUFFICIENT" in text: return "Google 권한(Drive·Slides)이 없는 토큰입니다. 토큰을 다시 발급해 주세요(scripts/google_sheets_authorize.py)." if "invalid_grant" in text: @@ -161,7 +168,7 @@ def _friendly(exc: Exception) -> str: return "회의록 보드 폴더를 찾을 수 없습니다(MEETING_BOARD_FOLDER_ID·공유 드라이브 접근 권한 확인)." if status == 403: return "Google Drive·Slides 접근이 거부되었습니다(API 사용 설정·공유 드라이브 권한 확인)." - return f"Google 슬라이드 처리 실패({type(exc).__name__}{f' {status}' if status else ''})." + return f"Google 슬라이드 처리 실패({type(exc).__name__}{f' {status}' if status else ''}{f' {code}' if code else ''})." _CLIENT: GoogleSlidesClient | None = None diff --git a/tests/test_project_meeting_board.py b/tests/test_project_meeting_board.py index 157803b..4a7c184 100644 --- a/tests/test_project_meeting_board.py +++ b/tests/test_project_meeting_board.py @@ -90,6 +90,8 @@ class MeetingBoardTests(unittest.TestCase): with self.assertRaises(gs.GoogleSlidesError): off.open_week_board(folder_id="F", week_key="2026-10-05", title="t") self.assertIn("토큰을 다시 발급", gs._friendly(RuntimeError("invalid_scope: Bad Request"))) + self.assertIn("OAuth 클라이언트", gs._friendly(RuntimeError("('unauthorized_client: Unauthorized', {'error': 'unauthorized_client'})"))) + self.assertIn("만료·폐기", gs._friendly(RuntimeError("('invalid_grant: Bad Request', {})"))) def test_title_uses_month_week_and_period(self): self.assertEqual(api.meeting_board_title(date(2026, 10, 5)), "10월 2주차 (10/5~10/11)")