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:
12
apps/web/src/api/client.test.ts
Normal file
12
apps/web/src/api/client.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
@ -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}`, {
|
||||
|
||||
Reference in New Issue
Block a user