Skip to content

Commit

Permalink
fix/#61: axios 의 then, catch 에서 try catch 문으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yh-project committed Aug 31, 2024
1 parent c6403aa commit 7687f8e
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions ssh-web/src/pages/Information/InformationFetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,39 @@ export const InformationFetch = () => {
const [related, setRelated] = useState<IUserInfoMascot[]>([]);

useEffect(() => {
if (userinfoQuery.data.data.type === 'PARENT') {
getMyChildren()
.then((res) => {
setRelated(() => {
const newRelated: IUserInfoMascot[] = [];
res.data.forEach((child: IChild) => {
const newUserInfoMascot: IUserInfoMascot = {
src: getImgSrc(child.gender, 'CHILD'),
label: child.nickname,
};
newRelated.push(newUserInfoMascot);
const queryFamily = async () => {
if (userinfoQuery.data.data.type === 'PARENT') {
await getMyChildren()
.then((res) => {
setRelated(() => {
const newRelated: IUserInfoMascot[] = [];
res.data.forEach((child: IChild) => {
const newUserInfoMascot: IUserInfoMascot = {
src: getImgSrc(child.gender, 'CHILD'),
label: child.nickname,
};
newRelated.push(newUserInfoMascot);
});
return newRelated;
});
return newRelated;
});
})
.catch((err) => console.log(err));
} else {
getMyParents()
.then((res) => {
})
.catch((err) => console.log(err));
} else {
try {
const parent = await getMyParents();
setRelated(() => {
const newRelated: IUserInfoMascot = {
src: getImgSrc(res.data.gender, 'PARENT'),
label: res.data.nickname,
src: getImgSrc(parent.data.gender, 'PARENT'),
label: parent.data.nickname,
};
return [newRelated];
});
})
.catch(() => {
console.log('this is error for query parents');
} catch {
showToast('error', '연결된 부모님이 없습니다');
});
}
}
}
};
queryFamily();
}, []);

return (
Expand Down

0 comments on commit 7687f8e

Please sign in to comment.