Skip to content

Commit

Permalink
fix: コンソールにAbortエラーが出ているのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
narirou committed Dec 4, 2024
1 parent 0e2c11e commit 555d3e8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 33 deletions.
10 changes: 8 additions & 2 deletions frontend/app/contexts/simulator-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -195,7 +201,7 @@ export const SimulatorProvider = ({ children }: { children: ReactNode }) => {
}
}, []);

const request = useClientChairNotification(simulateChairData?.id);
const chairNotification = useClientChairNotification(simulateChairData?.id);

const [currentCoodinate, setCurrentCoordinate] = useState<Coordinate>(() => {
const coordinate = getSimulatorCurrentCoordinate();
Expand All @@ -208,7 +214,7 @@ export const SimulatorProvider = ({ children }: { children: ReactNode }) => {
targetChair: simulateChairData
? {
...simulateChairData,
chairNotification: request,
chairNotification,
coordinateState: {
setter: setCurrentCoordinate,
coordinate: currentCoodinate,
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/contexts/user-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
24 changes: 10 additions & 14 deletions frontend/app/routes/client._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -150,6 +143,9 @@ export default function Index() {
});
setDisplayedChairs(chairs);
} catch (error) {
if (error instanceof DOMException && error.name === "AbortError") {
return;
}
console.error(error);
}
};
Expand Down
6 changes: 1 addition & 5 deletions frontend/app/routes/client.history/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ export default function Index() {
const [rides, setRides] = useState<Ride[]>([]);

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 (
Expand Down
17 changes: 5 additions & 12 deletions frontend/app/routes/owner.sales/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 555d3e8

Please sign in to comment.