Fakultas Ilmu Komputer UI

Commit 83197446 authored by FadhilP's avatar FadhilP
Browse files

add error handling in Topic get req

parent 995249d2
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
"web-vitals": "^0.2.4" "web-vitals": "^0.2.4"
}, },
"scripts": { "scripts": {
"start": "set PORT=3000 && react-scripts start", "start": "node server/server.js",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
......
...@@ -11,19 +11,19 @@ export default function Topic(props){ ...@@ -11,19 +11,19 @@ export default function Topic(props){
useEffect(() => { useEffect(() => {
const fetch = async () => { const fetch = async () => {
const responseThreads = await axios.get(`${API_URL}/threads/`) try {
const responseTopics = await axios.get(`${API_URL}/topics`) const responseThreads = await axios.get(`${API_URL}/threads/`)
const responseTopics = await axios.get(`${API_URL}/topics`)
const topic = responseTopics.data.data.find(topic => topic.name === topicParam).id const topic = responseTopics.data.data.find(topic => topic.name === topicParam).id
const threads = responseThreads.data.data.filter(thread => thread.topic_id === topic) const threads = responseThreads.data.data.filter(thread => thread.topic_id === topic)
const sortedThreads = threads.sort((a, b) => { const sortedThreads = threads.sort((a, b) => {
if (a.id < b.id) return 1 if (a.id < b.id) return 1
if (a.id > b.id) return -1 if (a.id > b.id) return -1
return 0 return 0
}) })
setThread(sortedThreads) setThread(sortedThreads)
console.log(threads) } catch(error){}
} }
fetch() fetch()
}, [topicParam]) }, [topicParam])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment