Files
siftlode/frontend/src/lib/youtubeErrors.ts
T
peter 1c6b7a9a5a feat(ui): R3 S3 — surface swallowed errors
- notifyYouTubeActionError: on any non-403 error, show the server's own reason (err.detail, e.g.
  "Not enough quota left today") instead of the caller's generic fallback, which was discarded
  (U-3.2.8). 403 still offers the Connect affordance.
- App boot error now offers a Retry (StateMessage) instead of a dead "Something went wrong" (U-4.2).
- deletePlaylist prefers the server's reason over a blanket "couldn't delete on YouTube" that
  misleads when the failure wasn't the YouTube side.
- Already covered in earlier sprints (verified): the live-search "Load more" already surfaces the
  quota error inline via err.detail, and ChannelPage subscribe/unsubscribe already route through
  notifyYouTubeActionError.
2026-07-22 04:43:02 +02:00

30 lines
1.3 KiB
TypeScript

import { HttpError } from "./api";
import { notify } from "./notifications";
import i18n from "../i18n";
// A YouTube-gated action (subscribe, sync, backfill, unsubscribe) that 403s means the user hasn't
// granted the write scope — surface a "Connect" affordance instead of a vague failure. Pass
// `onConnect` to offer the connect-wizard button (callers that have no wizard handle, e.g. the
// channel page, just get the message). `fallbackMessage` is the already-translated non-403 error.
export function notifyYouTubeActionError(
err: unknown,
fallbackMessage: string,
onConnect?: () => void,
): void {
const httpErr = err instanceof HttpError ? err : null;
if (httpErr?.status === 403) {
// A 403 on a YouTube write action means the write scope isn't granted — offer to connect.
notify({
level: "error",
message: i18n.t("channels.notify.needYouTube"),
action: onConnect
? { label: i18n.t("channels.notify.connect"), onClick: onConnect }
: undefined,
});
return;
}
// Any other error: prefer the server's own reason (e.g. "Not enough quota left today") over the
// caller's generic fallback — the useful detail was being discarded (U-3.2.8).
notify({ level: "error", message: httpErr?.detail || fallbackMessage });
}