fix: FCM must not break ingest; add requests dependency (0.9.3)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -69,7 +69,12 @@ def _fcm_access_token(service_account_path: str) -> str:
|
||||
from google.oauth2 import service_account
|
||||
from google.auth.transport.requests import Request
|
||||
except ImportError as exc:
|
||||
raise MobileNotConfiguredError("google-auth package is required for FCM") from exc
|
||||
msg = str(exc).lower()
|
||||
if "requests" in msg:
|
||||
raise MobileNotConfiguredError(
|
||||
"FCM: установите пакет requests (pip install requests)"
|
||||
) from exc
|
||||
raise MobileNotConfiguredError("FCM: установите google-auth") from exc
|
||||
|
||||
creds = service_account.Credentials.from_service_account_file(
|
||||
service_account_path,
|
||||
@@ -116,7 +121,19 @@ def _send_fcm_data(
|
||||
raise MobileNotConfiguredError("FCM не настроен на сервере")
|
||||
return
|
||||
|
||||
access_token = _fcm_access_token(cfg.service_account_path)
|
||||
try:
|
||||
access_token = _fcm_access_token(cfg.service_account_path)
|
||||
except (MobileNotConfiguredError, MobileSendError) as exc:
|
||||
logger.warning("FCM skipped: %s", exc)
|
||||
if require_success:
|
||||
raise
|
||||
return
|
||||
except Exception:
|
||||
logger.exception("FCM token acquisition failed")
|
||||
if require_success:
|
||||
raise MobileSendError("Failed to obtain FCM access token", status_code=502)
|
||||
return
|
||||
|
||||
url = f"https://fcm.googleapis.com/v1/projects/{cfg.project_id}/messages:send"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {access_token}",
|
||||
|
||||
Reference in New Issue
Block a user