Skip to content

Commit

Permalink
Catch error, function
Browse files Browse the repository at this point in the history
  • Loading branch information
ProchaLu committed Oct 24, 2024
1 parent fdec7a6 commit 70e748d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
28 changes: 13 additions & 15 deletions app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,21 @@ export default function App() {
useCallback(() => {
if (!isStale) return;

const getGuests = async () => {
try {
const response = await fetch('/api/guests', {
headers: {
Cookie: 'name=value',
},
});
const body: GuestsResponseBodyGet = await response.json();
async function getGuests() {
const response = await fetch('/api/guests', {
headers: {
Cookie: 'name=value',
},
});
const body: GuestsResponseBodyGet = await response.json();

setGuests(body.guests);
setIsStale(false);
} catch (error) {
console.error('Error fetching guests', error);
}
};
setGuests(body.guests);
setIsStale(false);
}

getGuests().catch(() => {});
getGuests().catch((error) => {
console.error(error);
});
}, [isStale]),
);

Expand Down
4 changes: 3 additions & 1 deletion app/(tabs)/newGuest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export default function NewGuest() {
if (body.error) {
errorMessage = body.error;
}
} catch {}
} catch (error) {
console.error(error);
}

Alert.alert('Error', errorMessage, [{ text: 'OK' }]);
return;
Expand Down
28 changes: 13 additions & 15 deletions app/guests/[guestId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,22 @@ export default function GuestPage() {

useFocusEffect(
useCallback(() => {
const loadGuest = async () => {
try {
if (typeof guestId !== 'string') {
return;
}
async function loadGuest() {
if (typeof guestId !== 'string') {
return;
}

const response = await fetch(`/api/${guestId}`);
const body: { guest: Guest } = await response.json();
const response = await fetch(`/api/${guestId}`);
const body: { guest: Guest } = await response.json();

setFirstName(body.guest.firstName);
setLastName(body.guest.lastName);
setAttending(body.guest.attending);
} catch (error) {
console.error('Error fetching guest', error);
}
};
setFirstName(body.guest.firstName);
setLastName(body.guest.lastName);
setAttending(body.guest.attending);
}

loadGuest().catch(() => {});
loadGuest().catch((error) => {
console.error(error);
});
}, [guestId]),
);

Expand Down

0 comments on commit 70e748d

Please sign in to comment.