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

@@ -44,16 +44,17 @@ let Profile = ({ navigation, route }) => {
console.log('Loading Cache Profile:' + route.params.profileid);
await API.getUserProfile(route.params.profileid).then((profileObj) => {
if(!subscribed) return 0;
let profile = profileObj.profile
setProfile(profileObj);
navigation.setOptions({ title: profile.firstName + " " + profile.lastName });
const nextProfile = profileObj && profileObj._id ? profileObj : {};
const profileData = nextProfile.profile || {};
setProfile(nextProfile);
navigation.setOptions({ title: (profileData.firstName || "") + " " + (profileData.lastName || "") });
});
await getProfilePosts(route.params.profileid).then(setPosts);
console.log('Loaded Cache Profile:' + route.params.profileid);
API.getPosts(route.params.profileid).then((data) => {
setLoading(false);
if(!subscribed) return 0;
setPosts(data);
setPosts(Array.isArray(data) ? data : []);
storeProfilePosts(route.params.profileid, data);
console.log('Store Cache Profile:' + route.params.profileid);
});
@@ -62,7 +63,7 @@ let Profile = ({ navigation, route }) => {
console.log('Getting posts with tag', tag)
API.getPostsWithTag(route.params.profileid, tag).then((data) => {
if(!subscribed) return 0;
setPosts(data.posts);
setPosts(Array.isArray(data?.posts) ? data.posts : []);
});
} else {
// if no profile information is pressent should load feed
@@ -80,7 +81,7 @@ let Profile = ({ navigation, route }) => {
API.getPostsWithTag(tag).then((data) => {
//if(!subscribed) return 0;
console.log(data.posts);
setPosts(data.posts);
setPosts(Array.isArray(data?.posts) ? data.posts : []);
});
}
@@ -148,7 +149,7 @@ let Profile = ({ navigation, route }) => {
maxToRenderPerBatch={3}
removeClippedSubviews={true}
onRefresh={() => {
API.getPosts(route.params.profileid).then(setPosts);
API.getPosts(route.params.profileid).then((data) => setPosts(Array.isArray(data) ? data : []));
}}
/> :
<></> //TODO: Add empty profile card here