diff --git a/frontend/app/contexts/simulator-context.tsx b/frontend/app/contexts/simulator-context.tsx index 169b88ed..47585ea9 100644 --- a/frontend/app/contexts/simulator-context.tsx +++ b/frontend/app/contexts/simulator-context.tsx @@ -65,6 +65,9 @@ export const useClientChairNotification = (id?: string) => { setNotification(json ? { ...json, contentType: "json" } : undefined); } } catch (error) { + if (error instanceof DOMException && error.name === "AbortError") { + return; + } console.error(error); } }; @@ -159,6 +162,9 @@ export const useClientChairNotification = (id?: string) => { }); timeoutId = setTimeout(() => void polling(), retryAfterMs); } catch (error) { + if (error instanceof DOMException && error.name === "AbortError") { + return; + } console.error(error); } }; @@ -195,7 +201,7 @@ export const SimulatorProvider = ({ children }: { children: ReactNode }) => { } }, []); - const request = useClientChairNotification(simulateChairData?.id); + const chairNotification = useClientChairNotification(simulateChairData?.id); const [currentCoodinate, setCurrentCoordinate] = useState(() => { const coordinate = getSimulatorCurrentCoordinate(); @@ -208,7 +214,7 @@ export const SimulatorProvider = ({ children }: { children: ReactNode }) => { targetChair: simulateChairData ? { ...simulateChairData, - chairNotification: request, + chairNotification, coordinateState: { setter: setCurrentCoordinate, coordinate: currentCoodinate, diff --git a/frontend/app/contexts/user-context.tsx b/frontend/app/contexts/user-context.tsx index 8a8d5db9..7c64a898 100644 --- a/frontend/app/contexts/user-context.tsx +++ b/frontend/app/contexts/user-context.tsx @@ -163,6 +163,9 @@ export const useClientAppRequest = (accessToken: string, id?: string) => { }); timeoutId = setTimeout(() => void polling(), retryAfterMs); } catch (error) { + if (error instanceof DOMException && error.name === "AbortError") { + return; + } if (isClientApiError(error)) { console.error(error.message); } diff --git a/frontend/app/routes/client._index/route.tsx b/frontend/app/routes/client._index/route.tsx index b9cdbbb9..6e853696 100644 --- a/frontend/app/routes/client._index/route.tsx +++ b/frontend/app/routes/client._index/route.tsx @@ -89,26 +89,19 @@ export default function Index() { if (!currentLocation || !destLocation) { return; } - const abortController = new AbortController(); - fetchAppPostRidesEstimatedFare( - { - body: { - pickup_coordinate: currentLocation, - destination_coordinate: destLocation, - }, + fetchAppPostRidesEstimatedFare({ + body: { + pickup_coordinate: currentLocation, + destination_coordinate: destLocation, }, - abortController.signal, - ) + }) .then((res) => setEstimatePrice({ fare: res.fare, discount: res.discount }), ) - .catch((err) => { - console.error(err); + .catch((error) => { + console.error(error); setEstimatePrice(undefined); }); - return () => { - abortController.abort(); - }; }, [currentLocation, destLocation]); const handleRideRequest = useCallback(async () => { @@ -150,6 +143,9 @@ export default function Index() { }); setDisplayedChairs(chairs); } catch (error) { + if (error instanceof DOMException && error.name === "AbortError") { + return; + } console.error(error); } }; diff --git a/frontend/app/routes/client.history/route.tsx b/frontend/app/routes/client.history/route.tsx index 878a9722..467a30b9 100644 --- a/frontend/app/routes/client.history/route.tsx +++ b/frontend/app/routes/client.history/route.tsx @@ -22,18 +22,14 @@ export default function Index() { const [rides, setRides] = useState([]); useEffect(() => { - const abortController = new AbortController(); void (async () => { try { - const res = await fetchAppGetRides({}, abortController.signal); + const res = await fetchAppGetRides({}); setRides(res.rides); } catch (error) { console.error(error); } })(); - return () => { - abortController.abort(); - }; }, []); return ( diff --git a/frontend/app/routes/owner.sales/route.tsx b/frontend/app/routes/owner.sales/route.tsx index f44a1f36..6beef6f3 100644 --- a/frontend/app/routes/owner.sales/route.tsx +++ b/frontend/app/routes/owner.sales/route.tsx @@ -45,27 +45,20 @@ export default function Index() { const since = salesDate?.since; const until = salesDate?.until; if (!since || !until) return; - let abortController: AbortController | undefined; void (async () => { try { - abortController = new AbortController(); setSales( - await fetchOwnerGetSales( - { - queryParams: { - until: timestamp(until), - since: timestamp(since), - }, + await fetchOwnerGetSales({ + queryParams: { + until: timestamp(until), + since: timestamp(since), }, - abortController.signal, - ), + }), ); } catch (error) { console.error(error); } })(); - - return () => abortController?.abort(); }, [salesDate, setSales]); const chairModelMap = useMemo(