Platform backbone (plan 2026-10-13-plattform-rueckgrat), all tasks reviewed: - webhooks with delivery table, retries and stable delivery id - calendar handlers; a finished task removes its Outlook event - tasks, automations, inspections, varroa, treatments, feedings, harvests, colonies, wintering, stock and bottling record domain events in the same transaction; legacy post-commit calls removed - row locks through one helper (lockRowForUpdate, lockRowsForShare, lockRowsForUpdate) - job framework with JobRun, cli exit codes, cleanup, task templates, daily evaluation, hourly app-backup and the rekey job - system API and page "Verwaltung > System" with retry - @nestjs/schedule removed, guard tests against in-process schedulers Field capture T3 (plan 2026-10-13-t3-erfassung-am-stand), all tasks reviewed: - inspection photo offline without metadata - bulk capture for treatments, feedings and varroa (backend + frontend) - offline stand mode with service worker, offline pages and packs - offline session, cold start and logout on shared devices Docs: ARCHITECTURE.md assumptions and sections updated, TASKS.md. Gates: backend lint, typecheck, 1770 unit, 420 e2e, build, no schema drift; frontend lint, typecheck, 913 tests, build. Not rolled out. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { listPacks } from "@/lib/apiaries/offline-pack";
|
|
import type { StoredPack } from "./db";
|
|
import { isNetworkError } from "@/lib/http/fetch-with-timeout";
|
|
|
|
/**
|
|
* The server's answer - or, only when the network failed, what the user's
|
|
* offline packs say. A server refusal (ApiError: 403, 404, 400 ...) is never
|
|
* covered up with pack data: the server knows better than an old pack.
|
|
* When the packs have nothing (`fromPacks` returns null) or cannot be read,
|
|
* the network error is passed on, so the caller shows "not loaded".
|
|
*
|
|
* Queries built on this read local storage when offline: give them
|
|
* `networkMode: "always"`, or a paused retry would hide the fallback.
|
|
*/
|
|
export async function withPackFallback<T>(
|
|
fetcher: () => Promise<T>,
|
|
fromPacks: (packs: StoredPack[]) => T | null,
|
|
ownerUserId: string,
|
|
): Promise<T> {
|
|
try {
|
|
return await fetcher();
|
|
} catch (error) {
|
|
if (!isNetworkError(error)) {
|
|
throw error;
|
|
}
|
|
const fallback = await listPacks(ownerUserId).then(fromPacks, () => null);
|
|
if (fallback === null) {
|
|
throw error;
|
|
}
|
|
return fallback;
|
|
}
|
|
}
|