💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve error handling
Vishnu Mohandasacd832fcd3d0
diff --git a/web/apps/locker/src/components/CreateItemDialog.tsx b/web/apps/locker/src/components/CreateItemDialog.tsxindex d7ed31a31e..7f9a13eabd 100644--- a/web/apps/locker/src/components/CreateItemDialog.tsx+++ b/web/apps/locker/src/components/CreateItemDialog.tsx@@ -10,6 +10,7 @@ import {DialogTitle,IconButton,InputAdornment,+ Link,Stack,TextField,Typography,@@ -43,7 +44,12 @@ import React, {useRef,useState,} from "react";-import { formatLockerMutationError } from "services/locker-errors";+import { Trans } from "react-i18next";+import {+ formatLockerMutationError,+ lockerUpgradeCTAType,+ type LockerUpgradeCTAType,+} from "services/locker-errors";import type { LockerUploadProgress } from "services/remote";import type {LockerCollection,@@ -178,6 +184,8 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({const [saving, setSaving] = useState(false);const [uploading, setUploading] = useState(false);const [error, setError] = useState<string | null>(null);+ const [upgradeCTAType, setUpgradeCTAType] =+ useState<LockerUpgradeCTAType | null>(null);const [formData, setFormData] = useState<Record<string, string>>(editItem ? (editItem.data as Record<string, string>) : {},);@@ -277,6 +285,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({);resetUploadState();setError(null);+ setUpgradeCTAType(null);}, [defaultCollectionID,editCollectionID,@@ -356,6 +365,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({setFormData({});setShowPassword(false);setError(null);+ setUpgradeCTAType(null);}, [isEditMode, saving, uploading]);const handleDialogClose = useCallback(@@ -383,6 +393,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({setSelectedCollectionNamesByFileKey({});resetUploadState();setError(null);+ setUpgradeCTAType(null);},[resetUploadState],);@@ -390,6 +401,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({const handleFieldChange = useCallback((field: string, value: string) => {setFormData((previous) => ({ ...previous, [field]: value }));setError(null);+ setUpgradeCTAType(null);}, []);const handleFileSelect = useCallback(@@ -414,6 +426,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({);resetUploadState();setError(null);+ setUpgradeCTAType(null);}},[resetUploadState, selectedCollectionIDs],@@ -433,6 +446,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({setSaving(true);setError(null);+ setUpgradeCTAType(null);try {const cleanData = Object.fromEntries(Object.entries(formData)@@ -444,6 +458,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({} catch (error) {log.error("Failed to save Locker item", error);setError(await formatLockerMutationError(error, "createItem"));+ setUpgradeCTAType(await lockerUpgradeCTAType(error));} finally {setSaving(false);}@@ -463,6 +478,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({setUploading(true);setError(null);+ setUpgradeCTAType(null);const pendingUploadFileKeys = new Set(pendingUploadItems.map((item) => uploadQueueItemKey(item)),);@@ -533,6 +549,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({)) {setError(t("required_field"));+ setUpgradeCTAType(null);return;}@@ -586,6 +603,11 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({"uploadFile",);setError((current) => current ?? formattedError);+ if (!upgradeCTAType) {+ setUpgradeCTAType(+ await lockerUpgradeCTAType(error),+ );+ }setFailedFileKeys((current) =>new Set(current).add(fileKey),);@@ -620,6 +642,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({} catch (error) {log.error("Failed to upload Locker files", error);setError(await formatLockerMutationError(error, "uploadFile"));+ setUpgradeCTAType(await lockerUpgradeCTAType(error));} finally {setUploading(false);}@@ -631,6 +654,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({onUploadItemComplete,onUploadsFinished,completedFileKeys,+ upgradeCTAType,selectedCollectionNamesByFileKey,selectedUploadItems,]);@@ -656,6 +680,8 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({const savedUploadCount = completedFileKeys.size;const totalUploadCount = selectedUploadItems.length;const showUploadCounter = isFileMode && totalUploadCount > 0;+ const shouldShowDialogErrorCard =+ !!error && (isFileMode || upgradeCTAType === "fileCountLimit");return (<Dialog@@ -729,6 +755,46 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({: {}),}}>+ {shouldShowDialogErrorCard && (+ <Box+ sx={(theme) => ({+ mb: 2.5,+ px: 2,+ py: 1.5,+ borderRadius: "16px",+ border: `1px solid ${theme.vars.palette.critical.main}22`,+ backgroundColor: `${theme.vars.palette.critical.main}12`,+ })}+ >+ <Typography+ variant="small"+ sx={{ color: "critical.main", fontWeight: 600 }}+ >+ {upgradeCTAType === "fileCountLimit" ? (+ <Trans+ i18nKey="uploadFileCountLimitErrorBodyWithUpgrade"+ components={{+ cta: (+ <Link+ href="https://web.ente.io"+ target="_blank"+ rel="noreferrer"+ underline="always"+ sx={{+ color: "critical.main",+ fontWeight: 700,+ }}+ />+ ),+ }}+ />+ ) : (+ error+ )}+ </Typography>+ </Box>+ )}+{!isEditMode && !selectedOption && (<Stack sx={{ gap: 2, pt: 0.5 }}><Typography variant="body" sx={{ color: "text.muted" }}>@@ -766,7 +832,6 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({uploadProgressByFileKey={uploadProgressByFileKey}uploadCapByFileKey={uploadCapByFileKey}uploading={uploading}- error={error}canUpload={canUpload}onFileSelect={handleFileSelect}onToggleCollectionName={(fileKey, name) =>@@ -854,7 +919,7 @@ export const CreateItemDialog: React.FC<CreateItemDialogProps> = ({/>)}- {error && (+ {error && upgradeCTAType !== "fileCountLimit" && (<Typographyvariant="small"sx={{ color: "critical.main" }}diff --git a/web/apps/locker/src/components/createItemDialog/FileUploadSection.tsx b/web/apps/locker/src/components/createItemDialog/FileUploadSection.tsxindex 78b10178d3..28a47d7dc1 100644--- a/web/apps/locker/src/components/createItemDialog/FileUploadSection.tsx+++ b/web/apps/locker/src/components/createItemDialog/FileUploadSection.tsx@@ -54,7 +54,6 @@ interface FileUploadSectionProps {uploadProgressByFileKey: Record<string, LockerUploadProgress | null>;uploadCapByFileKey: Record<string, number>;uploading: boolean;- error: string | null;canUpload: boolean;onFileSelect: (event: React.ChangeEvent<HTMLInputElement>) => void;onToggleCollectionName: (fileKey: string, name: string) => void;@@ -78,7 +77,6 @@ export function FileUploadSection({uploadProgressByFileKey,uploadCapByFileKey,uploading,- error,canUpload,onFileSelect,onToggleCollectionName,@@ -358,14 +356,6 @@ export function FileUploadSection({</Stack>)}- {error && (- <Typography- variant="small"- sx={{ color: "critical.main" }}- >- {error}- </Typography>- )}</Stack><Stack@@ -549,7 +539,7 @@ const UploadItemCard = React.memo(function UploadItemCard({sx={{ color: "text.muted", fontSize: 20, flexShrink: 0 }}/>)}- {canRemove && (+ {canRemove && !isDone && !isFailed && (<IconButtonaria-label={t("delete")}onClick={onRemove}diff --git a/web/apps/locker/src/locales/en-US/translation.json b/web/apps/locker/src/locales/en-US/translation.jsonindex d16e02800f..ca3beba2d3 100644--- a/web/apps/locker/src/locales/en-US/translation.json+++ b/web/apps/locker/src/locales/en-US/translation.json@@ -60,6 +60,7 @@"uploadStorageLimitErrorBody": "You've run out of storage space. Free up space to continue uploading.","uploadSubscriptionExpiredErrorBody": "Your Ente Photos subscription has expired. Renew your subscription to continue uploading.","uploadFileCountLimitErrorBody": "You've reached your file limit. Upgrade to a paid plan for more storage.",+ "uploadFileCountLimitErrorBodyWithUpgrade": "You've reached your file limit. Please <cta>upgrade</cta> to a paid plan.","uploadFileCountLimitErrorToast": "Action failed. You've reached your file limit.","uploadFileTooLargeErrorBody": "This file is larger than the maximum supported upload size of 10GB.","download": "Download",diff --git a/web/apps/locker/src/locales/fr-FR/translation.json b/web/apps/locker/src/locales/fr-FR/translation.jsonindex 5215cbe6f2..9e4dc9f0f3 100644--- a/web/apps/locker/src/locales/fr-FR/translation.json+++ b/web/apps/locker/src/locales/fr-FR/translation.json@@ -76,6 +76,7 @@"failedToLoadCollections": "Echec du chargement des collections : {{error}}","deleteFileConfirmation": "Es-tu sur de vouloir supprimer <strong>{{fileName}}</strong> ?","personalNote": "Note",+ "uploadFileCountLimitErrorBodyWithUpgrade": "Vous avez atteint votre limite de fichiers. Veuillez <cta>passer a une offre payante</cta>.","saveDocumentTitle": "Document","document": "Document","results": "Resultats",diff --git a/web/apps/locker/src/locales/ja-JP/translation.json b/web/apps/locker/src/locales/ja-JP/translation.jsonindex f622e6e10e..c39333c439 100644--- a/web/apps/locker/src/locales/ja-JP/translation.json+++ b/web/apps/locker/src/locales/ja-JP/translation.json@@ -75,6 +75,7 @@"dropToSaveToLocker": "ドロップしてLockerに保存","create": "作成","cancel": "キャンセル",+ "uploadFileCountLimitErrorBodyWithUpgrade": "ファイル数の上限に達しました。<cta>アップグレード</cta>して有料プランをご利用ください。","upload": "アップロード","close": "閉じる","logout": "ログアウト",diff --git a/web/apps/locker/src/services/locker-errors.ts b/web/apps/locker/src/services/locker-errors.tsindex 7f42c99217..9f3cb68f45 100644--- a/web/apps/locker/src/services/locker-errors.ts+++ b/web/apps/locker/src/services/locker-errors.ts@@ -2,6 +2,7 @@ import { HTTPError } from "ente-base/http";import { t } from "i18next";type LockerMutationAction = "createItem" | "uploadFile";+export type LockerUpgradeCTAType = "fileCountLimit" | "storageLimit";const museumErrorCode = async (error: HTTPError) => {try {@@ -43,3 +44,20 @@ export const formatLockerMutationError = async (return t(action === "uploadFile" ? "uploadError" : "failedToSaveRecord");};++export const lockerUpgradeCTAType = async (+ error: unknown,+): Promise<LockerUpgradeCTAType | null> => {+ if (!(error instanceof HTTPError)) {+ return null;+ }++ if (error.res.status === 426) {+ return "storageLimit";+ }++ const code = await museumErrorCode(error);+ return error.res.status === 403 && code === "FILE_LIMIT_REACHED"+ ? "fileCountLimit"+ : null;+};