From ad00742b5a5abbd286a14e08dcafcf7c4e9ad827 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Fri, 25 Jul 2025 23:53:33 +0100 Subject: [PATCH 1/2] fix: unexpected error submitting test drive expense --- .../TestDrive/Modal/EmployeeTestDriveModal.tsx | 7 ++++--- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/libs/Errors/AccountExistsError.ts | 13 +++++++++++++ src/libs/actions/Onboarding.ts | 6 ++++-- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/libs/Errors/AccountExistsError.ts diff --git a/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx b/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx index c93caf877b9e..2a2112d33f6a 100644 --- a/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx +++ b/src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx @@ -18,6 +18,7 @@ import { } from '@libs/actions/IOU'; import {verifyTestDriveRecipient} from '@libs/actions/Onboarding'; import setTestReceipt from '@libs/actions/setTestReceipt'; +import type AccountExistsError from '@libs/Errors/AccountExistsError'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {TestDriveModalNavigatorParamList} from '@libs/Navigation/types'; @@ -86,13 +87,13 @@ function EmployeeTestDriveModal() { }, () => { setIsLoading(false); - setFormError(translate('testDrive.modal.employee.error')); + setFormError(translate('common.genericErrorMessage')); }, ); }) - .catch(() => { + .catch((e: AccountExistsError) => { setIsLoading(false); - setFormError(translate('testDrive.modal.employee.error')); + setFormError(e.translationKey ? translate(e.translationKey) : 'common.genericErrorMessage'); }); }; diff --git a/src/languages/en.ts b/src/languages/en.ts index 583c5b9c0187..ed65ce8139b4 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -616,6 +616,7 @@ const translations = { getTheApp: 'Get the app', scanReceiptsOnTheGo: 'Scan receipts from your phone', headsUp: 'Heads up!', + unstableInternetConnection: 'Unstable internet connection. Please check your network and try again.', }, supportalNoAccess: { title: 'Not so fast', diff --git a/src/languages/es.ts b/src/languages/es.ts index 7848e4cc9a25..fa4e1f3fe87a 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -607,6 +607,7 @@ const translations = { getTheApp: 'Descarga la app', scanReceiptsOnTheGo: 'Escanea recibos desde tu teléfono', headsUp: '¡Atención!', + unstableInternetConnection: 'Conexión a internet inestable. Por favor, revisa tu red e inténtalo de nuevo.', }, supportalNoAccess: { title: 'No tan rápido', diff --git a/src/libs/Errors/AccountExistsError.ts b/src/libs/Errors/AccountExistsError.ts new file mode 100644 index 000000000000..4bf3ca199b7f --- /dev/null +++ b/src/libs/Errors/AccountExistsError.ts @@ -0,0 +1,13 @@ +import type {TranslationPaths} from '@src/languages/types'; + +class AccountExistsError extends Error { + translationKey: TranslationPaths; + + constructor(accountExists: boolean | undefined) { + super(); + // If accountExists is undefined, it means we couldn't determine the account status due to an unstable internet connection. + this.translationKey = accountExists === undefined ? 'common.unstableInternetConnection' : 'testDrive.modal.employee.error'; + } +} + +export default AccountExistsError; diff --git a/src/libs/actions/Onboarding.ts b/src/libs/actions/Onboarding.ts index 27f8f2e5e2b6..2bc087d0ccea 100644 --- a/src/libs/actions/Onboarding.ts +++ b/src/libs/actions/Onboarding.ts @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import * as API from '@libs/API'; import {SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types'; +import AccountExistsError from '@libs/Errors/AccountExistsError'; import ONYXKEYS from '@src/ONYXKEYS'; /** @@ -34,12 +35,13 @@ function setWorkspaceCurrency(currency: string) { function verifyTestDriveRecipient(email: string) { // eslint-disable-next-line rulesdir/no-api-side-effects-method return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.VERIFY_TEST_DRIVE_RECIPIENT, {email}).then((response) => { - if (!response?.accountExists) { + // If accountExists is undefined, it means we couldn't determine the account status due to an unstable internet connection. + if (response?.accountExists === false) { // We can invite this user since they do not have an account yet return; } - throw new Error(response?.message); + throw new AccountExistsError(response?.accountExists); }); } From 3e7441899c36ff934175eb6d8d2036a6cd8a19d9 Mon Sep 17 00:00:00 2001 From: Pedro Guerreiro Date: Tue, 29 Jul 2025 03:30:15 +0100 Subject: [PATCH 2/2] chore: add missing translations --- src/languages/de.ts | 1 + src/languages/fr.ts | 1 + src/languages/it.ts | 1 + src/languages/ja.ts | 1 + src/languages/nl.ts | 1 + src/languages/pl.ts | 1 + src/languages/pt-BR.ts | 1 + src/languages/zh-hans.ts | 1 + 8 files changed, 8 insertions(+) diff --git a/src/languages/de.ts b/src/languages/de.ts index 01641b41b076..ef30788f290e 100644 --- a/src/languages/de.ts +++ b/src/languages/de.ts @@ -627,6 +627,7 @@ const translations = { getTheApp: 'Hole dir die App', scanReceiptsOnTheGo: 'Scannen Sie Belege von Ihrem Telefon aus', headsUp: 'Achtung!', + unstableInternetConnection: 'Instabile Internetverbindung. Bitte überprüfe dein Netzwerk und versuche es erneut.', }, supportalNoAccess: { title: 'Nicht so schnell', diff --git a/src/languages/fr.ts b/src/languages/fr.ts index 7ebd9afa5cdc..3474fbeae01a 100644 --- a/src/languages/fr.ts +++ b/src/languages/fr.ts @@ -627,6 +627,7 @@ const translations = { getTheApp: "Obtenez l'application", scanReceiptsOnTheGo: 'Numérisez les reçus depuis votre téléphone', headsUp: 'Attention !', + unstableInternetConnection: 'Connexion Internet instable. Veuillez vérifier votre réseau et réessayer.', }, supportalNoAccess: { title: 'Pas si vite', diff --git a/src/languages/it.ts b/src/languages/it.ts index 4d142f10e1db..334a13754fe9 100644 --- a/src/languages/it.ts +++ b/src/languages/it.ts @@ -627,6 +627,7 @@ const translations = { getTheApp: "Scarica l'app", scanReceiptsOnTheGo: 'Scansiona le ricevute dal tuo telefono', headsUp: 'Attenzione!', + unstableInternetConnection: 'Connessione Internet instabile. Controlla la tua rete e riprova.', }, supportalNoAccess: { title: 'Non così in fretta', diff --git a/src/languages/ja.ts b/src/languages/ja.ts index b764681c4d68..733d63cfdaa5 100644 --- a/src/languages/ja.ts +++ b/src/languages/ja.ts @@ -627,6 +627,7 @@ const translations = { getTheApp: 'アプリを入手', scanReceiptsOnTheGo: '携帯電話から領収書をスキャンする', headsUp: 'ご注意ください!', + unstableInternetConnection: 'インターネット接続が不安定です。ネットワークを確認してもう一度お試しください。', }, supportalNoAccess: { title: 'ちょっと待ってください', diff --git a/src/languages/nl.ts b/src/languages/nl.ts index 575bfe75fa8e..d514b29c9a8f 100644 --- a/src/languages/nl.ts +++ b/src/languages/nl.ts @@ -626,6 +626,7 @@ const translations = { getTheApp: 'Download de app', scanReceiptsOnTheGo: 'Scan bonnetjes vanaf je telefoon', headsUp: 'Let op!', + unstableInternetConnection: 'Onstabiele internetverbinding. Controleer je netwerk en probeer het opnieuw.', }, supportalNoAccess: { title: 'Niet zo snel', diff --git a/src/languages/pl.ts b/src/languages/pl.ts index 390ea10d533e..ed11dfb2afc2 100644 --- a/src/languages/pl.ts +++ b/src/languages/pl.ts @@ -627,6 +627,7 @@ const translations = { getTheApp: 'Pobierz aplikację', scanReceiptsOnTheGo: 'Skanuj paragony za pomocą telefonu', headsUp: 'Uwaga!', + unstableInternetConnection: 'Niestabilne połączenie internetowe. Sprawdź swoją sieć i spróbuj ponownie.', }, supportalNoAccess: { title: 'Nie tak szybko', diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts index ee4ecda3ef84..33c69ef0f59e 100644 --- a/src/languages/pt-BR.ts +++ b/src/languages/pt-BR.ts @@ -626,6 +626,7 @@ const translations = { getTheApp: 'Obtenha o aplicativo', scanReceiptsOnTheGo: 'Digitalize recibos com seu celular', headsUp: 'Atenção!', + unstableInternetConnection: 'Conexão de internet instável. Verifique sua rede e tente novamente.', }, supportalNoAccess: { title: 'Não tão rápido', diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts index 3d185cef6e12..902bbc8736a1 100644 --- a/src/languages/zh-hans.ts +++ b/src/languages/zh-hans.ts @@ -626,6 +626,7 @@ const translations = { getTheApp: '获取应用程序', scanReceiptsOnTheGo: '用手机扫描收据', headsUp: '\u6CE8\u610F\uFF01', + unstableInternetConnection: '互联网连接不稳定。请检查你的网络,然后重试。', }, supportalNoAccess: { title: '慢一点',