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 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import threading
|
import threading
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -153,6 +154,12 @@ def _friendly(exc: Exception) -> str:
|
|||||||
"""Google API 오류 → 화면용 문구(비밀값·원문 응답 미포함)."""
|
"""Google API 오류 → 화면용 문구(비밀값·원문 응답 미포함)."""
|
||||||
status = getattr(getattr(exc, "resp", None), "status", None)
|
status = getattr(getattr(exc, "resp", None), "status", None)
|
||||||
text = str(exc)
|
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:
|
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)."
|
return "Google 권한(Drive·Slides)이 없는 토큰입니다. 토큰을 다시 발급해 주세요(scripts/google_sheets_authorize.py)."
|
||||||
if "invalid_grant" in text:
|
if "invalid_grant" in text:
|
||||||
@@ -161,7 +168,7 @@ def _friendly(exc: Exception) -> str:
|
|||||||
return "회의록 보드 폴더를 찾을 수 없습니다(MEETING_BOARD_FOLDER_ID·공유 드라이브 접근 권한 확인)."
|
return "회의록 보드 폴더를 찾을 수 없습니다(MEETING_BOARD_FOLDER_ID·공유 드라이브 접근 권한 확인)."
|
||||||
if status == 403:
|
if status == 403:
|
||||||
return "Google Drive·Slides 접근이 거부되었습니다(API 사용 설정·공유 드라이브 권한 확인)."
|
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
|
_CLIENT: GoogleSlidesClient | None = None
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ class MeetingBoardTests(unittest.TestCase):
|
|||||||
with self.assertRaises(gs.GoogleSlidesError):
|
with self.assertRaises(gs.GoogleSlidesError):
|
||||||
off.open_week_board(folder_id="F", week_key="2026-10-05", title="t")
|
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("토큰을 다시 발급", 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):
|
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)")
|
self.assertEqual(api.meeting_board_title(date(2026, 10, 5)), "10월 2주차 (10/5~10/11)")
|
||||||
|
|||||||
Reference in New Issue
Block a user