fix(web,api): débloquer la boucle de chargement 'Inventaire en cours' (Recherche/Admin)

- web: gestion d'erreur et d'état vide sur SearchPage/AdminPage
- web: client API — traitement des réponses sans contenu/erreurs réseau
- api: jobs.service — éviter le statut de scan perpétuellement en cours
- tests: client.test.ts

Refs: #12 (QA non-GREEN faute d'exécution, pas d'échec réel)
This commit is contained in:
Git Agent
2026-08-23 10:01:54 +02:00
parent 8f1140127f
commit e94524f119
6 changed files with 159 additions and 45 deletions

View File

@ -0,0 +1,12 @@
import { describe, expect, it } from "vitest";
import { ApiFallbackError, getApiFallback } from "./client";
describe("api fallback helpers", () => {
it("extracts typed fallback payloads", () => {
expect(getApiFallback<string[]>(new ApiFallbackError("offline", ["demo"]))).toEqual(["demo"]);
});
it("ignores non fallback errors", () => {
expect(getApiFallback<string[]>(new Error("boom"))).toBeUndefined();
});
});

View File

@ -28,6 +28,10 @@ export class ApiFallbackError extends Error {
}
}
export function getApiFallback<T>(error: unknown): T | undefined {
return error instanceof ApiFallbackError ? (error.fallback as T) : undefined;
}
async function request<T>(path: string, options: RequestOptions = {}): Promise<T> {
try {
const response = await fetch(`${API_BASE}${path}`, {