debug(sync): expose le corps d'erreur YouTube (reason) + log yt-channels

This commit is contained in:
2026-09-27 08:14:26 -04:00
parent f038f19b71
commit 720367fe13
2 changed files with 22 additions and 3 deletions
+3
View File
@@ -578,6 +578,9 @@ r.get('/oauth/google/yt-channels', authMiddlewareCookieAware, oauthLimiter, asyn
const out = { error: error?.message || 'yt_channels_failed' };
if (error?.detail) out.detail = error.detail;
if (error?.hint) out.hint = error.hint;
try {
console.warn(`[oauth] yt-channels échec user=${req.user?.id} code=${out.error} detail=${String(error?.detail || '').slice(0, 300)}`);
} catch {}
return res.status(error?.status || 502).json(out);
}
});
+19 -3
View File
@@ -642,13 +642,29 @@ async function getAuthedInnertube(conn, { pageId } = {}) {
return innertube;
}
/** Détail d'erreur YouTube exposable (clé API masquée, 300 car. max, sans token). */
/** Détail d'erreur YouTube exposable (clé/token masqués, 500 car. max). */
function libErrorDetail(e) {
try {
return String(e?.message || e || '')
// youtubei.js met le corps de réponse dans e.info (JSON d'erreur Google).
let raw = '';
if (e?.info && typeof e.info === 'object') {
try { raw = JSON.stringify(e.info); } catch { raw = String(e.info); }
} else if (typeof e?.info === 'string') {
raw = e.info;
}
const combined = [raw, String(e?.message || '')].filter(Boolean).join(' | ');
// Extrait le motif Google s'il existe : {"error":{"errors":[{"reason":"X"}]}}.
let reason = '';
try {
const parsed = JSON.parse(raw);
const first = parsed?.error?.errors?.[0];
if (first?.reason) reason = `reason=${first.reason}; msg=${String(first.message || parsed?.error?.message || '').slice(0, 200)}`;
} catch {}
const out = (reason || combined)
.replace(/key=[^&\s]*/gi, 'key=[redacted]')
.replace(/Bearer\s+[A-Za-z0-9._~-]+/gi, 'Bearer [redacted]')
.slice(0, 300) || undefined;
.slice(0, 500);
return out || undefined;
} catch { return undefined; }
}