From 28274b3fc712dee4b7649adeb4947ba4e5252d73 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sat, 10 Apr 2021 20:52:38 -0400 Subject: [PATCH] improve Group page API --- src/components/Group.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Group.tsx b/src/components/Group.tsx index 4a6ba93..a2cef80 100644 --- a/src/components/Group.tsx +++ b/src/components/Group.tsx @@ -38,12 +38,17 @@ const SAMPLE_POOLS: Carpool.Pool[] = [ export default function Group() { // eslint-disable-next-line const { id } = useParams<{ id: string }>(); + const [error, setError] = useState(false); const [group, setGroup] = useState(); const [pools, setPools] = useState(SAMPLE_POOLS); useEffect(() => { makeAPIGetCall('/group', { groupID: id }).then((res) => { - setGroup(res.data.data); + if ('error' in res.data) { + setError(true); + } else { + setGroup(res.data.data); + } }); makeAPIGetCall('/group_pools', { groupID: id }).then((res) => { @@ -51,6 +56,10 @@ export default function Group() { }); }, [id]); + if (error) { + return

Group Not Found

; + } + if (!group) { return

Loading

; }