Report why each Plex connection failed
build-container / build (push) Successful in 2m25s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 5.5 committed 2026-10-20 14:11:37 -04:00
1 parent 943f510ec4
commit cd48ccf8e0
1 file changed
+7 -4
+7 -4
View File
@@ -198,15 +198,18 @@ async function plexApi(req, res) {
if (!r) return json(res, 404, { error: 'Server not found' });
// Prefer direct remote connections, then relay, then local; first one that answers wins.
const order = c => (c.local ? 2 : c.relay ? 1 : 0);
const tried = [];
for (const c of [...r.connections].sort((a, b) => order(a) - order(b))) {
const label = (c.local ? 'local ' : c.relay ? 'relay ' : 'remote ') + new URL(c.uri).hostname.replace(/\.[0-9a-f]{20,}\.plex\.direct$/, '');
try {
const t = await fetch(c.uri + '/identity', { headers: { ...PLEX_HEADERS, 'X-Plex-Token': r.accessToken }, signal: AbortSignal.timeout(4000) });
if (!t.ok) continue;
const t = await fetch(c.uri + '/identity', { headers: { ...PLEX_HEADERS, 'X-Plex-Token': r.accessToken }, signal: AbortSignal.timeout(6000) });
if (!t.ok) { tried.push(`${label}: HTTP ${t.status}`); continue; }
setCookies(req, res, { plex_srv: signed(c.uri), plex_stk: r.accessToken, plex_name: r.name });
return json(res, 200, { ok: true, name: r.name });
} catch {}
} catch (e) { tried.push(`${label}: ${e.cause?.code || e.name || e.message}`); }
}
return json(res, 502, { error: 'Could not reach this server. Check that Remote Access is enabled in Plex.' });
console.error('Plex connect failed for', r.name, tried);
return json(res, 502, { error: 'Could not reach this server. Tried: ' + tried.slice(0, 4).join('; ') });
}
if (u.pathname === '/api/plex/logout' && req.method === 'POST') {
setCookies(req, res, { plex_token: '', plex_srv: '', plex_stk: '', plex_name: '' });