diff --git a/packages/filesystem/dropbox/dropbox.test.ts b/packages/filesystem/dropbox/dropbox.test.ts index 14d0e5078..43a239127 100644 --- a/packages/filesystem/dropbox/dropbox.test.ts +++ b/packages/filesystem/dropbox/dropbox.test.ts @@ -14,4 +14,20 @@ describe("DropboxFileSystem", () => { await expect(fs.delete("missing.txt")).resolves.toBeUndefined(); }); + + it("exists should return false on path not found", async () => { + const fs = new DropboxFileSystem("/", "token"); + vi.spyOn(fs, "request").mockRejectedValue( + new Error('Dropbox API Error: 409 - {"error_summary":"path/not_found/..."}') + ); + + await expect(fs.exists("/missing.txt")).resolves.toBe(false); + }); + + it("exists should rethrow auth and network errors", async () => { + const fs = new DropboxFileSystem("/", "token"); + vi.spyOn(fs, "request").mockRejectedValue(new Error("Dropbox API Error: 401 - invalid_access_token")); + + await expect(fs.exists("/test.txt")).rejects.toThrow("invalid_access_token"); + }); }); diff --git a/packages/filesystem/dropbox/dropbox.ts b/packages/filesystem/dropbox/dropbox.ts index 9550b67f4..46c264322 100644 --- a/packages/filesystem/dropbox/dropbox.ts +++ b/packages/filesystem/dropbox/dropbox.ts @@ -4,6 +4,11 @@ import type { FileInfo, FileCreateOptions, FileReader, FileWriter } from "../fil import { joinPath } from "../utils"; import { DropboxFileReader, DropboxFileWriter } from "./rw"; +function isDropboxPathNotFound(error: unknown): boolean { + const message = error instanceof Error ? error.message : String(error); + return message.includes("path_lookup/not_found") || message.includes("path/not_found"); +} + export default class DropboxFileSystem implements FileSystem { accessToken?: string; @@ -149,7 +154,7 @@ export default class DropboxFileSystem implements FileSystem { }), }); } catch (e: any) { - if (e.message?.includes("path_lookup/not_found") || e.message?.includes("path/not_found")) { + if (isDropboxPathNotFound(e)) { return; } throw e; @@ -241,8 +246,11 @@ export default class DropboxFileSystem implements FileSystem { }), }); return true; - } catch (_) { - return false; + } catch (e) { + if (isDropboxPathNotFound(e)) { + return false; + } + throw e; } }