diff --git a/src/lib/api/documents.test.ts b/src/lib/api/documents.test.ts index 80afc0d84..5ec5f25e6 100644 --- a/src/lib/api/documents.test.ts +++ b/src/lib/api/documents.test.ts @@ -150,6 +150,16 @@ describe("document uploads and processing", () => { expect(p).toMatchObject(pending); }); }); + + test("pending error", async () => { + const mockFetch = vi.fn().mockImplementation(async () => { + throw new Error("Bad fetch"); + }); + + documents.pending(mockFetch).then((p) => { + expect(p).toEqual([]); + }); + }); }); describe("document helper methods", () => { diff --git a/src/lib/api/documents.ts b/src/lib/api/documents.ts index 444c50599..d2e7bd4ba 100644 --- a/src/lib/api/documents.ts +++ b/src/lib/api/documents.ts @@ -163,19 +163,22 @@ export async function process( */ export async function cancel(id: number | string) {} +/** + * Get pending documents. This returns an empty array for any error. + * + * @param {fetch} fetch + * @returns {Promise} + */ export async function pending(fetch = globalThis.fetch): Promise { const endpoint = new URL("documents/pending/", BASE_API_URL); - // if this request fails for any reason, just return nothing - const resp = await fetch(endpoint, { credentials: "include" }).catch((e) => ({ - ok: false, - json() { - return []; - }, - })); - - // if there's an error above, this will return an empty array - return resp.json(); + try { + const resp = await fetch(endpoint, { credentials: "include" }); + if (isErrorCode(resp.status)) return []; + return resp.json(); + } catch (e) { + return []; + } } // utility functions diff --git a/src/lib/components/documents/ResultsList.svelte b/src/lib/components/documents/ResultsList.svelte index 439edd1ac..e2d2b2e08 100644 --- a/src/lib/components/documents/ResultsList.svelte +++ b/src/lib/components/documents/ResultsList.svelte @@ -87,7 +87,7 @@
- + {#each results as document (document.id)} @@ -131,6 +131,8 @@ {/if}
+ +