Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Conv

Manav Rathi6512820653e8
diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.ts
index 5b22475e4a..1229248530 100644
--- a/web/apps/photos/src/services/upload-manager.ts
+++ b/web/apps/photos/src/services/upload-manager.ts
@@ -20,7 +20,9 @@ import {
} from "ente-gallery/services/upload/metadata-json";
import UploadService, {
areLivePhotoAssets,
+ isUploadCancelledError,
upload,
+ uploadCancelledErrorMessage,
uploadItemFileName,
type PotentialLivePhotoAsset,
type UploadAsset,
@@ -37,7 +39,6 @@ import { FileType } from "ente-media/file-type";
import { potentialFileTypeFromExtension } from "ente-media/live-photo";
import { getLocalFiles } from "ente-new/photos/services/files";
import { indexNewUpload } from "ente-new/photos/services/ml";
-import { CustomError } from "ente-shared/error";
import { wait } from "ente-utils/promise";
import {
getLocalPublicFiles,
@@ -378,7 +379,7 @@ class UploadManager {
await this.uploadMediaItems(clusteredMediaItems);
}
} catch (e) {
- if (e.message != CustomError.UPLOAD_CANCELLED) {
+ if (!isUploadCancelledError(e)) {
log.error("Upload failed", e);
throw e;
}
@@ -436,7 +437,7 @@ class UploadManager {
private abortIfCancelled = () => {
if (this.shouldUploadBeCancelled) {
- throw Error(CustomError.UPLOAD_CANCELLED);
+ throw new Error(uploadCancelledErrorMessage);
}
};
diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.ts
index c1a4f1437e..190e7d5a83 100644
--- a/web/packages/gallery/services/upload/upload-service.ts
+++ b/web/packages/gallery/services/upload/upload-service.ts
@@ -543,6 +543,9 @@ const uploadItemCreationDate = async (
* The message of the {@link Error} that is thrown when the user cancels an
* upload.
*
+ * As a convenience, the {@link isUploadCancelledError} matcher can be used to
+ * match such errors.
+ *
* [Note: Upload cancellation]
*
* 1. User cancels the upload by pressing the cancel button on the upload
@@ -561,6 +564,13 @@ const uploadItemCreationDate = async (
*/
export const uploadCancelledErrorMessage = "Upload cancelled";
+/**
+ * A convenience function to check if the provided value is an {@link Error}
+ * with message {@link uploadCancelledErrorMessage}.
+ */
+export const isUploadCancelledError = (e: unknown) =>
+ e instanceof Error && e.message == uploadCancelledErrorMessage;
+
/**
* Some state and callbacks used during upload that are not tied to a specific
* file being uploaded.
@@ -741,12 +751,12 @@ export const upload = async (
uploadedFile,
};
} catch (e) {
- if (e instanceof Error && e.message == CustomError.UPLOAD_CANCELLED) {
- log.info(`Upload for ${fileName} cancelled`);
- } else {
- log.error(`Upload failed for ${fileName}`, e);
+ if (isUploadCancelledError(e)) {
+ // Nothing to do for these, just relay them up.
+ throw e;
}
+ log.error(`Upload failed for ${fileName}`, e);
const error = handleUploadError(e);
switch (error.message) {
case CustomErrorMessage.eTagMissing:
@@ -1618,8 +1628,8 @@ const uploadToBucket = async (
* used by the upload subsystem.
*
* @param abortIfCancelled A function that aborts the operation by throwing a
- * error with the message set to {@link CustomError.UPLOAD_CANCELLED} if the
- * user has cancelled the upload.
+ * error with the message set to {@link uploadCancelledErrorMessage} if the user
+ * has cancelled the upload.
*
* @return A function of type {@link HTTPRequestRetrier} that can be used to
* retry requests. This function will retry requests (obtained afresh each time
@@ -1641,11 +1651,7 @@ const createAbortableRetryEnsuringHTTPOk =
{
...opts,
abortIfNeeded(e) {
- if (
- e instanceof Error &&
- e.message == CustomError.UPLOAD_CANCELLED
- )
- throw e;
+ if (isUploadCancelledError(e)) throw e;
},
},
);
diff --git a/web/packages/shared/error/index.ts b/web/packages/shared/error/index.ts
index 29d5d04013..014af48a68 100644
--- a/web/packages/shared/error/index.ts
+++ b/web/packages/shared/error/index.ts
@@ -41,7 +41,6 @@ export const CustomError = {
BAD_REQUEST: "bad request",
SUBSCRIPTION_NEEDED: "subscription not present",
NOT_FOUND: "not found ",
- UPLOAD_CANCELLED: "upload cancelled",
UPDATE_EXPORTED_RECORD_FAILED: "update file exported record failed",
EXPORT_STOPPED: "export stopped",
EXPORT_FOLDER_DOES_NOT_EXIST: "export folder does not exist",
@@ -84,7 +83,8 @@ export function handleUploadError(error: any): Error {
case CustomError.SUBSCRIPTION_EXPIRED:
case CustomError.STORAGE_QUOTA_EXCEEDED:
case CustomError.SESSION_EXPIRED:
- case CustomError.UPLOAD_CANCELLED:
+ // Not relevant here, add a hook in postEnteFile
+ // case CustomError.UPLOAD_CANCELLED:
throw parsedError;
}
return parsedError;