Skip to content

Commit ad00742

Browse files
committed
fix: unexpected error submitting test drive expense
1 parent 2bf343f commit ad00742

5 files changed

Lines changed: 23 additions & 5 deletions

File tree

src/components/TestDrive/Modal/EmployeeTestDriveModal.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '@libs/actions/IOU';
1919
import {verifyTestDriveRecipient} from '@libs/actions/Onboarding';
2020
import setTestReceipt from '@libs/actions/setTestReceipt';
21+
import type AccountExistsError from '@libs/Errors/AccountExistsError';
2122
import Navigation from '@libs/Navigation/Navigation';
2223
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
2324
import type {TestDriveModalNavigatorParamList} from '@libs/Navigation/types';
@@ -86,13 +87,13 @@ function EmployeeTestDriveModal() {
8687
},
8788
() => {
8889
setIsLoading(false);
89-
setFormError(translate('testDrive.modal.employee.error'));
90+
setFormError(translate('common.genericErrorMessage'));
9091
},
9192
);
9293
})
93-
.catch(() => {
94+
.catch((e: AccountExistsError) => {
9495
setIsLoading(false);
95-
setFormError(translate('testDrive.modal.employee.error'));
96+
setFormError(e.translationKey ? translate(e.translationKey) : 'common.genericErrorMessage');
9697
});
9798
};
9899

src/languages/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ const translations = {
616616
getTheApp: 'Get the app',
617617
scanReceiptsOnTheGo: 'Scan receipts from your phone',
618618
headsUp: 'Heads up!',
619+
unstableInternetConnection: 'Unstable internet connection. Please check your network and try again.',
619620
},
620621
supportalNoAccess: {
621622
title: 'Not so fast',

src/languages/es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ const translations = {
607607
getTheApp: 'Descarga la app',
608608
scanReceiptsOnTheGo: 'Escanea recibos desde tu teléfono',
609609
headsUp: '¡Atención!',
610+
unstableInternetConnection: 'Conexión a internet inestable. Por favor, revisa tu red e inténtalo de nuevo.',
610611
},
611612
supportalNoAccess: {
612613
title: 'No tan rápido',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type {TranslationPaths} from '@src/languages/types';
2+
3+
class AccountExistsError extends Error {
4+
translationKey: TranslationPaths;
5+
6+
constructor(accountExists: boolean | undefined) {
7+
super();
8+
// If accountExists is undefined, it means we couldn't determine the account status due to an unstable internet connection.
9+
this.translationKey = accountExists === undefined ? 'common.unstableInternetConnection' : 'testDrive.modal.employee.error';
10+
}
11+
}
12+
13+
export default AccountExistsError;

src/libs/actions/Onboarding.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Onyx from 'react-native-onyx';
22
import * as API from '@libs/API';
33
import {SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types';
4+
import AccountExistsError from '@libs/Errors/AccountExistsError';
45
import ONYXKEYS from '@src/ONYXKEYS';
56

67
/**
@@ -34,12 +35,13 @@ function setWorkspaceCurrency(currency: string) {
3435
function verifyTestDriveRecipient(email: string) {
3536
// eslint-disable-next-line rulesdir/no-api-side-effects-method
3637
return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.VERIFY_TEST_DRIVE_RECIPIENT, {email}).then((response) => {
37-
if (!response?.accountExists) {
38+
// If accountExists is undefined, it means we couldn't determine the account status due to an unstable internet connection.
39+
if (response?.accountExists === false) {
3840
// We can invite this user since they do not have an account yet
3941
return;
4042
}
4143

42-
throw new Error(response?.message);
44+
throw new AccountExistsError(response?.accountExists);
4345
});
4446
}
4547

0 commit comments

Comments
 (0)