Skip to content

Commit

Permalink
fix: ItemAutoList no longer fails after one network abort
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian-Webster committed Feb 16, 2024
1 parent faea8f8 commit 29e1bb5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/ItemAutoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FlatList, RefreshControl, TouchableOpacity } from "react-native";
import { View, Text } from "react-native";
import { useTheme } from "@react-navigation/native";
import { ActivityIndicator } from "react-native";
import axios from "axios";
import axios, { CanceledError } from "axios";
import { ServerUrlContext } from "./ServerUrlContext";
import ParseErrorMessage from "./ParseErrorMessage";
import Ionicons from 'react-native-vector-icons/Ionicons';
Expand All @@ -28,6 +28,10 @@ export default function ItemAutoList({noItemsFoundText, centreIfNoItems, url, ex

dispatch({type: 'addItems', items, noMoreItems})
}).catch(error => {
if (error instanceof CanceledError) {
return dispatch({type: 'error', error: 'Network request was cancelled because list was unmounted.'})
}

dispatch({type: 'error', error: ParseErrorMessage(error)})
console.error(error)
console.error(ParseErrorMessage(error))
Expand All @@ -41,6 +45,7 @@ export default function ItemAutoList({noItemsFoundText, centreIfNoItems, url, ex
return () => {
console.warn('Aborting network requests from ItemAutoList as component is getting unmounted.')
AbortControllerRef.current.abort();
AbortControllerRef.current = new AbortController();
}
}, [dispatch])

Expand Down

0 comments on commit 29e1bb5

Please sign in to comment.