Skip to content

Commit

Permalink
[FE/#15] Fix : useFetch try...catch 문 제대로 동작하도록 수정
Browse files Browse the repository at this point in the history
- try 문 안에 fetch 로직이 들어있지 않아 제대로 에러 핸들링이 되지 않으므로 감싸서 해결
  • Loading branch information
sungik-choi committed Jun 24, 2020
1 parent 2880b12 commit 53c17db
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions FE/src/hooks/useFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ const useFetch = ({
}) => {
const [loading, setLoading] = useState(true);
const getData = async () => {
const data = await fetch(url, option);
const { response } = await data.json();

try {
const data = await fetch(url, option);
const { response } = await data.json();
console.log("[log] data : ", response);
dispatch(fetchSuccess(response));
} catch (e) {
console.log("[log] error : ", response);
} catch (err) {
console.log("[log] error : ", err);
dispatch(fetchError());
}
setLoading(false);
Expand Down

0 comments on commit 53c17db

Please sign in to comment.