Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add 413 error message handler to mobile app (#1786)
Leendert de Borstc631326706a9
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppError.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppError.ktindex 00314c5eb..5b103dd76 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppError.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/AppError.kt@@ -269,6 +269,15 @@ sealed class AppError(message: String, cause: Throwable? = null) : Exception(mescause: Throwable? = null,) : AppError(message, cause)+ /**+ * Error indicating the server rejected the vault upload with HTTP 413+ * because the encrypted vault exceeds the configured MAX_UPLOAD_SIZE_MB limit.+ */+ class VaultTooLarge(+ message: String = "Vault too large for server",+ cause: Throwable? = null,+ ) : AppError(message, cause)+/*** Error indicating max sync retries reached.*/@@ -342,6 +351,7 @@ sealed class AppError(message: String, cause: Throwable? = null) : Exception(mesis VaultMergeFailed -> "E-701"is MergeUploadFailed -> "E-705"is VaultUploadFailed -> "E-801"+ is VaultTooLarge -> "E-804"is MaxRetriesReached -> "E-901"is UnknownError -> "E-001"is ParseError -> "E-002"diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultSync.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultSync.ktindex 2e4e45192..6fbd8cc39 100644--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultSync.kt+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultSync.kt@@ -247,6 +247,11 @@ class VaultSync(handleSyncError(AppError.VaultUploadFailed("Upload failed: ${uploadResult.error}"))}}+ } catch (e: AppError) {+ // Preserve typed AppError (e.g. VaultTooLarge → E-804) so the JS layer can show the targeted message.+ metadata.setIsSyncing(false)+ Log.e(TAG, "Upload sync error: ${e.message}", e)+ handleSyncError(e)} catch (e: Exception) {metadata.setIsSyncing(false)Log.e(TAG, "Upload sync error: ${e.message}", e)@@ -400,6 +405,12 @@ class VaultSync(}if (response.statusCode != 200) {+ // 413: server / reverse-proxy rejected the upload because the vault exceeded+ // MAX_UPLOAD_SIZE_MB. Throw a typed error so the JS layer gets E-804 and can+ // surface the targeted "vault too large" message instead of a generic failure.+ if (response.statusCode == 413) {+ throw AppError.VaultTooLarge()+ }return VaultUploadResult(success = false,status = -1,@@ -438,6 +449,10 @@ class VaultSync(mutationSeqAtStart = mutationSeqAtStart,error = if (vaultResponse.status != 0) "Vault upload returned status ${vaultResponse.status}" else null,)+ } catch (e: AppError) {+ // Let typed AppError (e.g. VaultTooLarge → E-804) propagate so performUploadSync can pass+ // it to handleSyncError with the correct error code instead of wrapping it as a generic upload failure.+ throw e} catch (e: Exception) {Log.e(TAG, "Error uploading vault", e)VaultUploadResult(diff --git a/apps/mobile-app/hooks/useVaultMutate.ts b/apps/mobile-app/hooks/useVaultMutate.tsindex d1f2139dd..cbf9bac36 100644--- a/apps/mobile-app/hooks/useVaultMutate.ts+++ b/apps/mobile-app/hooks/useVaultMutate.ts@@ -11,6 +11,9 @@ import EncryptionUtility from '@/utils/EncryptionUtility';import { useVaultSync } from '@/hooks/useVaultSync';+import { AppErrorCode, formatErrorWithCode } from '@/utils/types/errors/AppErrorCodes';+import { PayloadTooLargeError } from '@/utils/types/errors/PayloadTooLargeError';+import { useApp } from '@/context/AppContext';import { useDb } from '@/context/DbContext';import { useWebApi } from '@/context/WebApiContext';@@ -115,6 +118,15 @@ export function useVaultMutate() : {},onError: async (error) => {console.warn('Background sync failed:', error);+ /*+ * Surface the error to the user.+ */+ Toast.show({+ type: 'error',+ text1: t('common.error'),+ text2: error,+ position: 'bottom',+ });options.onError?.(new Error(error));},onOffline: async () => {@@ -268,6 +280,13 @@ export function useVaultMutate() : {options.onSuccess?.();} catch (error) {console.error('Error during password change operation:', error);+ if (error instanceof PayloadTooLargeError) {+ /*+ * Server rejected the upload with HTTP 413. Re-throw with a translated, coded error+ * so the UI can show a targeted "vault too large" message instead of a generic failure.+ */+ throw new Error(formatErrorWithCode(t('common.errors.vaultTooLarge'), AppErrorCode.UPLOAD_TOO_LARGE));+ }throw error;}}, [dbContext, authContext, webApi, prepareVaultForPasswordChange, t]);diff --git a/apps/mobile-app/hooks/useVaultSync.ts b/apps/mobile-app/hooks/useVaultSync.tsindex adda8f8d4..26aa4d5bd 100644--- a/apps/mobile-app/hooks/useVaultSync.ts+++ b/apps/mobile-app/hooks/useVaultSync.ts@@ -239,6 +239,7 @@ export const useVaultSync = (): {} finally {syncInProgressRef.current = false;dbContext.setIsSyncing(false);+ dbContext.setIsUploading(false);}}, [app, dbContext, t]);diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.jsonindex 156607974..e5671b820 100644--- a/apps/mobile-app/i18n/locales/en.json+++ b/apps/mobile-app/i18n/locales/en.json@@ -32,6 +32,7 @@"errors": {"unknownError": "An unknown error occurred.","unknownErrorTryAgain": "An unknown error occurred. Please try again.",+ "vaultTooLarge": "The vault is too large for the server to accept. Try to remove some items or attachments to reduce the size and try again.","serverVersionTooOld": "The AliasVault server needs to be updated to a newer version in order to use this feature. Please contact the server admin if you need help."}},diff --git a/apps/mobile-app/ios/VaultStoreKit/Enums/AppError.swift b/apps/mobile-app/ios/VaultStoreKit/Enums/AppError.swiftindex a8a23675a..7d7e518a4 100644--- a/apps/mobile-app/ios/VaultStoreKit/Enums/AppError.swift+++ b/apps/mobile-app/ios/VaultStoreKit/Enums/AppError.swift@@ -50,6 +50,10 @@ public enum AppError: Error {// Upload errorscase vaultUploadFailed(message: String)+ /// Server rejected the vault upload with HTTP 413 because the encrypted vault+ /// exceeds the configured MAX_UPLOAD_SIZE_MB limit on the server.+ case vaultTooLarge+// Retry errorscase maxRetriesReached@@ -134,6 +138,8 @@ public enum AppError: Error {return "E-705"case .vaultUploadFailed:return "E-801"+ case .vaultTooLarge:+ return "E-804"case .maxRetriesReached:return "E-901"case .unknownError:@@ -208,6 +214,8 @@ public enum AppError: Error {return "Upload after merge failed: \(message)"case .vaultUploadFailed(let message):return "Vault upload failed: \(message)"+ case .vaultTooLarge:+ return "Vault too large for server"case .maxRetriesReached:return "Max sync retries reached"case .unknownError(let message):diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Mutate.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Mutate.swiftindex 29e38d170..bbaf6d67b 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Mutate.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Mutate.swift@@ -258,6 +258,12 @@ extension VaultStore {// Check response statusguard response.statusCode == 200 else {+ // 413: server / reverse-proxy rejected the upload because the vault exceeded+ // MAX_UPLOAD_SIZE_MB. Throw a typed error so the JS layer gets E-804 and can+ // surface the targeted "vault too large" message instead of a generic failure.+ if response.statusCode == 413 {+ throw AppError.vaultTooLarge+ }return VaultUploadResult(success: false,status: -1,diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Sync.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Sync.swiftindex b15c2ace5..2eb732df4 100644--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Sync.swift+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Sync.swift@@ -363,6 +363,10 @@ extension VaultStore {error: uploadResult.error ?? "Upload failed")}+ } catch let error as AppError {+ // Preserve typed AppError (e.g. vaultTooLarge → E-804) so the JS layer can show the targeted message.+ setIsSyncing(false)+ return handleSyncError(error)} catch {setIsSyncing(false)return VaultSyncResult(@@ -522,6 +526,15 @@ extension VaultStore {wasOffline: false,error: error.code)+ case .vaultTooLarge:+ // Return the bare E-XXX code so the JS layer can map it to the localized vaultTooLarge message.+ return VaultSyncResult(+ success: false,+ action: .error,+ newRevision: getCurrentVaultRevisionNumber(),+ wasOffline: false,+ error: error.code+ )default:return VaultSyncResult(success: false,diff --git a/apps/mobile-app/utils/WebApiService.ts b/apps/mobile-app/utils/WebApiService.tsindex 7dbc3fea9..8098fa862 100644--- a/apps/mobile-app/utils/WebApiService.ts+++ b/apps/mobile-app/utils/WebApiService.ts@@ -6,6 +6,7 @@ import type { StatusResponse, VaultResponse, AuthLogModel, RefreshToken } from 'import i18n from '@/i18n';import { LocalAuthError } from './types/errors/LocalAuthError';+import { PayloadTooLargeError } from './types/errors/PayloadTooLargeError';import { logoutEventEmitter } from '@/events/LogoutEventEmitter';import NativeVaultManager from '@/specs/NativeVaultManager';@@ -91,6 +92,10 @@ export class WebApiService {throw new Error(i18n.t('auth.errors.sessionExpired'));}+ if (response.statusCode === 413 && throwOnError) {+ throw new PayloadTooLargeError(`Request rejected with HTTP 413: payload exceeds server limit`);+ }+if (response.statusCode >= 400 && throwOnError) {throw new Error(i18n.t('auth.errors.httpError', { status: response.statusCode }));}diff --git a/apps/mobile-app/utils/types/errors/AppErrorCodes.ts b/apps/mobile-app/utils/types/errors/AppErrorCodes.tsindex f46fa07f0..d734e540e 100644--- a/apps/mobile-app/utils/types/errors/AppErrorCodes.ts+++ b/apps/mobile-app/utils/types/errors/AppErrorCodes.ts@@ -72,6 +72,7 @@ export enum AppErrorCode {// Upload errors (E-8xx) - from VaultSync.ktUPLOAD_FAILED = 'E-801', // AppError: vault upload failed+ UPLOAD_TOO_LARGE = 'E-804', // Server rejected upload with HTTP 413 (vault exceeds MAX_UPLOAD_SIZE_MB)// Native module/retry errors (E-9xx)MAX_RETRIES_REACHED = 'E-901', // AppError: max sync retries reached@@ -228,6 +229,7 @@ export function getErrorTranslationKey(code: AppErrorCode): string {// Upload errors[AppErrorCode.UPLOAD_FAILED]: 'common.errors.unknownErrorTryAgain',+ [AppErrorCode.UPLOAD_TOO_LARGE]: 'common.errors.vaultTooLarge',// Native module/retry errors[AppErrorCode.MAX_RETRIES_REACHED]: 'common.errors.unknownErrorTryAgain',diff --git a/apps/mobile-app/utils/types/errors/PayloadTooLargeError.ts b/apps/mobile-app/utils/types/errors/PayloadTooLargeError.tsnew file mode 100644index 000000000..c2418c0e3--- /dev/null+++ b/apps/mobile-app/utils/types/errors/PayloadTooLargeError.ts@@ -0,0 +1,15 @@+/**+ * Thrown when the server rejects a request with HTTP 413 (Request Entity Too Large).+ * For vault uploads this signals the encrypted vault exceeds the server's MAX_UPLOAD_SIZE_MB limit.+ */+export class PayloadTooLargeError extends Error {+ /**+ * Creates a new instance of PayloadTooLargeError.+ *+ * @param message - The error message.+ */+ public constructor(message: string) {+ super(message);+ this.name = 'PayloadTooLargeError';+ }+}