Gracefully handle backend failures in Expo app

This commit is contained in:
Adolfo Reyna
2026-02-20 19:25:38 -05:00
parent fe9fc8e3e4
commit 009f1ec792
14 changed files with 205 additions and 97 deletions

View File

@@ -49,6 +49,7 @@ const handleURL = (url, navigation) => {
}
async function onFetchUpdateAsync() {
if (__DEV__) return;
try {
const update = await Updates.checkForUpdateAsync();
@@ -90,11 +91,11 @@ let Feed = ({ navigation, route }) => {
}
if (!route.params?.reRender) {
API.getMe().then((me) => {
if (subscribed) {
if (subscribed && me && me._id) {
GlobalState.me = me;
posthog.identify(me.userid,
{
name: me.profile.firstName,
name: me.profile?.firstName,
profileid: me._id,
is_superuser: me.superuser,
}
@@ -108,11 +109,12 @@ let Feed = ({ navigation, route }) => {
console.log("Feed from server")
}
await onFetchUpdateAsync();
flatListRef.current.scrollToOffset({ animated: true, offset: 0 })
flatListRef.current?.scrollToOffset({ animated: true, offset: 0 })
let posts = await API.getPosts();
if (subscribed) {
setPosts(posts);
storeFeed(posts);
const safePosts = Array.isArray(posts) ? posts : [];
setPosts(safePosts);
storeFeed(safePosts);
}
console.log("Feed, end useEffect")
}
@@ -141,7 +143,7 @@ let Feed = ({ navigation, route }) => {
//ListHeaderComponent={<NewPost newPostCB={(newPost) => setPosts([newPost, ...Posts])} />}
refreshing={Posts.length === 0}
onRefresh={() => {
API.getPosts().then(setPosts);
API.getPosts().then((data) => setPosts(Array.isArray(data) ? data : []));
}}
initialNumToRender={3}
maxToRenderPerBatch={3}