async function RequestValidation()

in frontend/app/DeliverableUploader/UploadService.ts [173:225]


async function RequestValidation(
  entry: FileEntry,
  uploadSlotId: string,
  sha1sum: string,
  attempt: number = 0
): Promise<boolean> {
  const targetUrl = `/deliverable-receiver/validate?uploadId=${uploadSlotId}&fileName=${
    entry.filename
  }&sum=${encodeURIComponent(sha1sum)}`;
  const token = localStorage.getItem("pluto:access-token");
  const response = await fetch(targetUrl, {
    method: "GET",
    headers: {
      "Content-Type": "application/octet-stream",
      Authorization: `Bearer ${token}`,
    },
  });
  const content = await response.text();
  switch (response.status) {
    case 200:
      console.log("Server reported successful validation for ", entry.filename);
      return true;
    case 409:
      console.log(
        "Server reported that checksums don't match for ",
        entry.filename,
        ": ",
        content
      );
      return false;
    case 403:
      console.error(
        "Server reported forbidden. Assuming expired credential and trying again in 3s..."
      );
      return new Promise<boolean>((resolve, reject) =>
        window.setTimeout(() => {
          RequestValidation(entry, uploadSlotId, sha1sum, attempt)
            .then(resolve)
            .catch(reject);
        }, 3000)
      );
    default:
      console.log("Unexpected error: ", content);
      let msg = content;
      try {
        const json = JSON.parse(content);
        msg = json.detail;
      } catch (err) {
        console.warn("could not parse error report as json: ", err);
      }
      throw msg;
  }
}