feat(channels): clearer error when a YouTube action lacks the scope

api: HttpError now carries the server's detail. Channels sync/backfill/unsubscribe
now detect a 403 (no YouTube grant) and show a 'connect your YouTube account'
message with a Connect action that opens the onboarding wizard, instead of a vague
'failed' toast. Translated HU/EN/DE.
This commit is contained in:
npeter83 2026-06-15 02:02:05 +02:00
parent ea317c0009
commit cdc15ad1f9
6 changed files with 43 additions and 10 deletions

View file

@ -95,9 +95,11 @@ export interface VersionInfo {
class HttpError extends Error {
status: number;
constructor(status: number) {
super(`HTTP ${status}`);
detail?: string; // server-provided reason (FastAPI's `detail`), when present
constructor(status: number, detail?: string) {
super(detail || `HTTP ${status}`);
this.status = status;
this.detail = detail;
}
}
@ -128,11 +130,19 @@ async function req(url: string, opts: RequestInit = {}): Promise<any> {
throw e;
}
if (!r.ok) {
// Capture the server's reason (FastAPI returns `{ detail }`) so callers can react.
let detail: string | undefined;
try {
const body = await r.json();
if (body && typeof body.detail === "string") detail = body.detail;
} catch {
/* no JSON body */
}
// Server faults are worth surfacing; 401/403/404 etc. are handled by callers.
if (r.status >= 500) {
notifyErrorThrottled(`Server error ${r.status}`, `${method} ${url}`);
}
throw new HttpError(r.status);
throw new HttpError(r.status, detail);
}
return r.status === 204 ? null : r.json();
}