diff --git a/apps/api/src/delivery/zerozero.ts b/apps/api/src/delivery/zerozero.ts index d9c5686..593cd3f 100644 --- a/apps/api/src/delivery/zerozero.ts +++ b/apps/api/src/delivery/zerozero.ts @@ -265,6 +265,9 @@ export class ZerozeroClient { /** Takes an uploaded image back. Already gone (or no longer this account's to remove) is not an error. */ async remove(imageId: string): Promise { + // "synced-" (from `upload`, when the desk already had the file) is not a real image id: there was + // never anything of ours to take back, and the desk answers a bare DELETE on it with 400, not 404. + if (!/^\d+$/.test(imageId)) return; await this.json(`/images/${encodeURIComponent(imageId)}`, { method: "DELETE" }).catch((err: unknown) => { if (err instanceof TransportError && /: (403|404)$/.test(err.message)) return; throw err; diff --git a/apps/api/test/zerozero-remove.test.ts b/apps/api/test/zerozero-remove.test.ts index 43ae706..8ee324c 100644 --- a/apps/api/test/zerozero-remove.test.ts +++ b/apps/api/test/zerozero-remove.test.ts @@ -39,4 +39,11 @@ describe("ZerozeroClient.remove", () => { expect(err).toBeInstanceOf(TransportError); expect((err as TransportError).transient).toBe(true); }); + + it("skips the call for a 'synced-' placeholder id: there was never a real image to take back", async () => { + const client = new ZerozeroClient({ username: "foto", password: "segredo" }, (() => { + throw new Error("should not call fetch"); + }) as unknown as typeof fetch); + await expect(client.remove("synced-PSR11532.jpg")).resolves.toBeUndefined(); + }); });