From c6fd85b4231837a289ca8e73937629f48dfce0d3 Mon Sep 17 00:00:00 2001 From: DVGY Date: Sat, 21 Oct 2023 21:41:12 +0530 Subject: [PATCH 1/2] types --- client/src/components/bookings/CheckoutForm.tsx | 10 +++++++--- client/src/components/trips/FilterTrips.tsx | 1 - client/src/components/trips/UserReviews.tsx | 2 +- client/src/components/user-menu/UserSettings.tsx | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/client/src/components/bookings/CheckoutForm.tsx b/client/src/components/bookings/CheckoutForm.tsx index e5e1e45..3d3b35b 100644 --- a/client/src/components/bookings/CheckoutForm.tsx +++ b/client/src/components/bookings/CheckoutForm.tsx @@ -82,11 +82,15 @@ const CheckoutForm: FC = ({ tripId, price }) => { if (responsePaymentResult.error) { setError(responsePaymentResult?.error); } - setLoading(false); } catch (error) { - setError(error); - setLoading(false); + if (error instanceof Error) { + console.log(error); + } else { + setError(error as unknown as StripeError); + } console.log(error); + } finally { + setLoading(false); } }; diff --git a/client/src/components/trips/FilterTrips.tsx b/client/src/components/trips/FilterTrips.tsx index 0736598..e44f700 100644 --- a/client/src/components/trips/FilterTrips.tsx +++ b/client/src/components/trips/FilterTrips.tsx @@ -135,7 +135,6 @@ const FilterTrips: FC = ({ size='xs' rightIcon={} fontSize={['xs', 'xs', 'xs', 'md', 'md', 'md']} - isFullWidth='true' textAlign='start' fontWeight='medium' > diff --git a/client/src/components/trips/UserReviews.tsx b/client/src/components/trips/UserReviews.tsx index 449b942..e32b75d 100644 --- a/client/src/components/trips/UserReviews.tsx +++ b/client/src/components/trips/UserReviews.tsx @@ -1,4 +1,4 @@ -import React, { FC } from 'react'; +import { FC } from 'react'; import { Flex, Text } from '@chakra-ui/react'; import { MdStar } from 'react-icons/md'; diff --git a/client/src/components/user-menu/UserSettings.tsx b/client/src/components/user-menu/UserSettings.tsx index c543d39..b1a49ba 100644 --- a/client/src/components/user-menu/UserSettings.tsx +++ b/client/src/components/user-menu/UserSettings.tsx @@ -1,4 +1,4 @@ -import React, { FC } from 'react'; +import { FC } from 'react'; import { Box } from '@chakra-ui/react'; const UserSettings: FC = () => { From ff45f9115f6fb3c2baff545ae9f976193827c7a8 Mon Sep 17 00:00:00 2001 From: DVGY Date: Sat, 21 Oct 2023 21:43:40 +0530 Subject: [PATCH 2/2] types --- client/src/hooks/useAPI.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/hooks/useAPI.tsx b/client/src/hooks/useAPI.tsx index 589e302..afb0b0d 100644 --- a/client/src/hooks/useAPI.tsx +++ b/client/src/hooks/useAPI.tsx @@ -4,6 +4,7 @@ import Axios from '../utils/Axios'; import { usePrevious } from './usePrevious'; import isDeepEqual from 'fast-deep-equal'; import { localStorageProxy } from '../utils/localStorageProxy'; +import { AxiosError } from 'axios'; export enum AxiosMethods { GET = 'get', @@ -75,11 +76,15 @@ const useAPI = ({ }, }); setResponse(data); - setLoading(false); } catch (error) { console.log(error); + if (error instanceof Error) { + setError(error.message); + } else if (error instanceof AxiosError) { + setError(error.response); + } + } finally { setLoading(false); - setError(error.response); } }; if (!isDeepEqual({ method, resource, query }, previousPropsRef)) {