Skip to content

requestFileHandles should return an empty list instead of throwing NotFoundError #53

@beaufortfrancois

Description

@beaufortfrancois

After more thoughts, I believe navigator.crossOriginStorage.requestFileHandles() should NOT throw NotFoundError when COS files are not found. It should simply return an empty list instead.

It's not an exception to not have found files, it's okay to not have them in the cache. A user saying no to the prompt OR an unexpected internal error should indeed throw exceptions.

const hash = {
  algorithm: "SHA-256",
  value: "8f434346648f6b96df89dda901c5176b10a6d83961dd3c1ac88b59b2dc327aa4",
};
let handle;
try {
  [handle] = await navigator.crossOriginStorage.requestFileHandles([hash]);
} catch (err) {
  if (err.name === "NotAllowedError")
    console.log("The user did not grant permission to access the file.");
}
if (handle) {
  const fileBlob = await handle.getFile();
  // Do something with the blob.
} else {
  console.log("The file was not found in Cross-Origin Storage.");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions