Skip to content

Commit

Permalink
use better types for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed May 21, 2024
1 parent d96b217 commit 9ef0e19
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 43 deletions.
10 changes: 2 additions & 8 deletions src/components/AttachmentPicker/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,8 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s
.then((result) => {
completeAttachmentSelection.current(result);
})
.catch((error) => {
let errorMessage;
if (error instanceof Error) {
errorMessage = error.message;
} else {
errorMessage = String(error.message);
}
showGeneralAlert(errorMessage);
.catch((error: Error) => {
showGeneralAlert(error.message);
throw error;
});
},
Expand Down
10 changes: 3 additions & 7 deletions src/components/Onfido/BaseOnfidoWeb.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Onfido as OnfidoSDK} from 'onfido-sdk-ui';
import type {ErrorType} from 'onfido-sdk-ui/types/Types';
import React, {forwardRef, useEffect} from 'react';
import type {ForwardedRef} from 'react';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
Expand Down Expand Up @@ -92,14 +93,9 @@ function initializeOnfido({sdkToken, onSuccess, onError, onUserExit, preferredLo
}
onSuccess(data);
},
onError: (error) => {
let errorMessage;
if (error instanceof Error) {
errorMessage = error.message;
} else {
errorMessage = CONST.ERROR.UNKNOWN_ERROR;
}
onError: (error: ErrorType) => {
const errorType = error.type;
const errorMessage: string = error.message ?? CONST.ERROR.UNKNOWN_ERROR;
Log.hmmm('Onfido error', {errorType, errorMessage});
if (errorType === CONST.WALLET.ERROR.ONFIDO_USER_CONSENT_DENIED) {
onUserExit();
Expand Down
10 changes: 3 additions & 7 deletions src/components/Onfido/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {OnfidoCaptureType, OnfidoCountryCode, OnfidoDocumentType, Onfido as OnfidoSDK, OnfidoTheme} from '@onfido/react-native-sdk';
import type {ErrorType} from 'onfido-sdk-ui/types/Types';
import React, {useEffect} from 'react';
import {Alert, Linking} from 'react-native';
import {checkMultiple, PERMISSIONS, RESULTS} from 'react-native-permissions';
Expand Down Expand Up @@ -29,13 +30,8 @@ function Onfido({sdkToken, onUserExit, onSuccess, onError}: OnfidoProps) {
},
})
.then(onSuccess)
.catch((error) => {
let errorMessage: string;
if (error instanceof Error) {
errorMessage = error.message;
} else {
errorMessage = CONST.ERROR.UNKNOWN_ERROR;
}
.catch((error: ErrorType) => {
const errorMessage: string = error.message ?? CONST.ERROR.UNKNOWN_ERROR;
const errorType = error.type;

Log.hmmm('Onfido error on native', {errorType, errorMessage});
Expand Down
6 changes: 3 additions & 3 deletions src/components/SignInButtons/AppleSignIn/index.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ function AppleSignIn() {
const handleSignIn = () => {
appleSignInRequest()
.then((token) => Session.beginAppleSignIn(token))
.catch((e) => {
if (e instanceof Error && e.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) {
.catch((error) => {
if (error instanceof Error && error.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) {
return null;
}
Log.alert('[Apple Sign In] Apple authentication failed', e);
Log.alert('[Apple Sign In] Apple authentication failed', error);

Check failure on line 44 in src/components/SignInButtons/AppleSignIn/index.android.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Parameters | undefined`
});
};
return (
Expand Down
10 changes: 1 addition & 9 deletions src/libs/actions/Device/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,7 @@ function setDeviceID() {
Log.info('Got new deviceID', false, uniqueID);
Onyx.set(ONYXKEYS.DEVICE_ID, uniqueID);
})
.catch((err) => {
let errorMessage;
if (err instanceof Error) {
errorMessage = err.message;
} else {
errorMessage = String(err.message);
}
Log.info('Found existing deviceID', false, errorMessage);
});
.catch((error: Error) => Log.info('Found existing deviceID', false, error.message));
}

/**
Expand Down
10 changes: 2 additions & 8 deletions tests/e2e/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,8 @@ const createServerInstance = (): ServerInstance => {
res.statusCode = 500;
res.end('Error executing command');
})
.catch((error) => {
let errorString;
if (error instanceof Error) {
errorString = error.toString();
} else {
errorString = String(error);
}
Logger.error('Error executing command', errorString);
.catch((error: string) => {
Logger.error('Error executing command', error);
res.statusCode = 500;
res.end('Error executing command');
});
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/collections/reportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ export default function createRandomReportAction(index: number): ReportAction {
};
}

export {getRandomDate, flattenActionNamesValues};
export {getRandomDate};

0 comments on commit 9ef0e19

Please sign in to comment.