Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Make API URL connection errors more descriptive (#1104)
Leendert de Borst747596615e44
diff --git a/apps/mobile-app/app/login.tsx b/apps/mobile-app/app/login.tsxindex 7df0e0909..b680e396f 100644--- a/apps/mobile-app/app/login.tsx+++ b/apps/mobile-app/app/login.tsx@@ -14,6 +14,7 @@ import type { LoginResponse, VaultResponse } from '@/utils/dist/shared/models/weimport EncryptionUtility from '@/utils/EncryptionUtility';import { SrpUtility } from '@/utils/SrpUtility';import { ApiAuthError } from '@/utils/types/errors/ApiAuthError';+import { LocalAuthError } from '@/utils/types/errors/LocalAuthError';import { useColors } from '@/hooks/useColorScheme';import { useTranslation } from '@/hooks/useTranslation';@@ -306,9 +307,15 @@ export default function LoginScreen() : React.ReactNode {if (err instanceof ApiAuthError) {console.error('ApiAuthError error:', err);setError(t(`apiErrors.${err.message}`));+ } else if (err instanceof LocalAuthError) {+ console.error('Network/SSL error:', err);+ // Use the error message as the translation key+ setError(t(`auth.errors.${(err as Error).message}`));} else {console.error('Login error:', err);- setError(t('auth.errors.serverError'));+ // Check if self-hosted to show appropriate server error message+ const isSelfHosted = await webApi.isSelfHosted();+ setError(t(isSelfHosted ? 'auth.errors.serverErrorSelfHosted' : 'auth.errors.serverError'));}setIsLoading(false);setLoginStatus(null);@@ -370,9 +377,13 @@ export default function LoginScreen() : React.ReactNode {console.error('2FA error:', err);if (err instanceof ApiAuthError) {setError(t(`apiErrors.${err.message}`));+ } else if ((err as { translationKey?: boolean })?.translationKey) {+ // Use the error message as the translation key+ setError(t(`auth.errors.${(err as Error).message}`));} else {- console.error('2FA error:', err);- setError(t('auth.errors.serverError'));+ // Check if self-hosted to show appropriate server error message+ const isSelfHosted = await webApi.isSelfHosted();+ setError(t(isSelfHosted ? 'auth.errors.serverErrorSelfHosted' : 'auth.errors.serverError'));}setIsLoading(false);}diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.jsonindex 45f9327b6..8d10f27ab 100644--- a/apps/mobile-app/i18n/locales/en.json+++ b/apps/mobile-app/i18n/locales/en.json@@ -44,6 +44,9 @@"incorrectPassword": "Incorrect password. Please try again.","enterPassword": "Please enter your password","serverError": "Could not reach AliasVault server. Please try again later or contact support if the problem persists.",+ "serverErrorSelfHosted": "Could not reach your self-hosted server. Please verify the API endpoint is reachable by navigating to it in a browser: it should display 'OK'.",+ "networkError": "Network request failed. Please check your internet connection and try again.",+ "networkErrorSelfHosted": "Network request failed. Check your network connection and server availability. For self-hosted instances, please ensure you have a valid SSL certificate installed. Self-signed certificates are not supported on mobile devices for security reasons.","incorrectPasswordFallback": "Incorrect password. Please try again."},"confirmLogout": "Are you sure you want to logout? You need to login again with your master password to access your vault.",diff --git a/apps/mobile-app/utils/WebApiService.ts b/apps/mobile-app/utils/WebApiService.tsindex cd8d3dbfc..a678da06d 100644--- a/apps/mobile-app/utils/WebApiService.ts+++ b/apps/mobile-app/utils/WebApiService.ts@@ -2,6 +2,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage';import { AppInfo } from '@/utils/AppInfo';import type { StatusResponse, VaultResponse, AuthLogModel, RefreshToken } from '@/utils/dist/shared/models/webapi';+import { LocalAuthError } from '@/utils/types/errors/LocalAuthError';type RequestInit = globalThis.RequestInit;@@ -122,6 +123,34 @@ export class WebApiService {return response;} catch (error) {console.error('API request failed:', error);++ // Detect SSL certificate errors+ if (error instanceof TypeError) {+ const errorMessage = error.message.toLowerCase();++ // Common SSL/TLS error patterns on iOS and Android+ if (errorMessage.includes('ssl') ||+ errorMessage.includes('tls') ||+ errorMessage.includes('cert') ||+ errorMessage.includes('trust') ||+ errorMessage.includes('self-signed') ||+ errorMessage.includes('ca') ||+ errorMessage.includes('network request failed')) {++ // Check if this is a self-hosted instance+ const isSelfHosted = await this.isSelfHosted();++ if (isSelfHosted) {+ // For self-hosted instances, throw error with translation key+ throw new LocalAuthError('networkErrorSelfHosted');+ } else {+ // For the default API URL, throw error with translation key+ throw new LocalAuthError('networkError');+ }+ }+ }++ // Re-throw the original error if it's not SSL-relatedthrow error;}}diff --git a/apps/mobile-app/utils/types/errors/LocalAuthError.ts b/apps/mobile-app/utils/types/errors/LocalAuthError.tsnew file mode 100644index 000000000..8f92ecad9--- /dev/null+++ b/apps/mobile-app/utils/types/errors/LocalAuthError.ts@@ -0,0 +1,14 @@+/**+ * Custom error class for API authentication-related errors.+ */+export class LocalAuthError extends Error {+ /**+ * Creates a new instance of LocalAuthError.+ *+ * @param message - The error message.+ */+ public constructor(message: string) {+ super(message);+ this.name = 'LocalAuthError';+ }+}