fix(ui): a write that fails says what failed and why, wherever it fails
`req` opens its blocking dialog for 400/409/422/5xx only. A 403/404/429 was left to the caller and a 502-504 or lost connection got just the self-clearing connection notice, so 34 mutations without a reporting onError and 15 direct api writes with a bare or missing catch failed in silence: a hidden channel that snapped back, a share link that never revoked, a confirmed account delete that ended with nothing said. - lib/queryClient: one MutationCache reporter. react-query awaits it BEFORE the mutation's own onError, so it waits a task and skips a failure the site already reported; the toast title comes from `meta.failTitle`, `meta.errorShownInline` opts out. - notifyActionError: title names WHAT failed, the line under it says WHY (`failureReason`: a structured localized detail, else the status). It marks the error reported (`markReported`), so nothing reports one failure twice; `notifyKnownFailure` for a site's own specific sentence. - Every silent site named (45 new HU/EN titles, 4 reasons). Stale "the global dialog shows it" comments corrected on the job actions, channel block, Plex sync, cookies, download enqueue, account delete and usePref. - Channels passed the tag hook's channel id to the reporter as the error; the tag and priority hooks now report themselves, with the real error. - A contract test keeps every useMutation naming its failure; CLAUDE.md gains the pattern row. - history.dom.test: the "navigates only once the entries are back" assertion raced an async act's macrotask flush (1 in 5 runs); it now asserts from a later popstate listener.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { MutationCache, QueryClient } from "@tanstack/react-query";
|
||||
import i18n from "../i18n";
|
||||
import { notifyActionError } from "./actionErrors";
|
||||
|
||||
declare module "@tanstack/react-query" {
|
||||
interface Register {
|
||||
mutationMeta: {
|
||||
/** i18n key of the toast title that names what failed ("Couldn't hide the channel"). Without
|
||||
* one the failure is still reported, under the generic "Couldn't complete that". */
|
||||
failTitle?: string;
|
||||
/** The component renders this mutation's failure on the page itself — no toast. */
|
||||
errorShownInline?: boolean;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
type FailMeta = { failTitle?: string; errorShownInline?: boolean } | undefined;
|
||||
|
||||
/**
|
||||
* The ONE reporter for a failed mutation. `req` shows its blocking dialog for 400/409/422/5xx only;
|
||||
* a 403/404/429 was left to the caller and a 502–504 or network failure got just the connection
|
||||
* notice — so every `useMutation` without a reporting `onError` failed in silence: a channel hide
|
||||
* that snapped back, a share link that never revoked, a scheduler run that never started (E11 S2b
|
||||
* counted 34 such mutations). Reporting centrally means a new mutation cannot be silent.
|
||||
*
|
||||
* react-query awaits this BEFORE the mutation's own `onError`, so it waits a task: a site that
|
||||
* reported the failure itself (through `notifyActionError`, which marks it) has had its turn, and
|
||||
* `notifyActionError` skips what is already on screen.
|
||||
*/
|
||||
function reportMutationFailure(err: unknown, meta: FailMeta): void {
|
||||
if (meta?.errorShownInline) return;
|
||||
setTimeout(() => notifyActionError(err, i18n.t(meta?.failTitle ?? "errors.title")), 0);
|
||||
}
|
||||
|
||||
export function createQueryClient(): QueryClient {
|
||||
return new QueryClient({
|
||||
mutationCache: new MutationCache({
|
||||
onError: (err, _vars, _onMutateResult, mutation) => reportMutationFailure(err, mutation.meta),
|
||||
}),
|
||||
defaultOptions: { queries: { retry: false, staleTime: 30_000, refetchOnWindowFocus: false } },
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user