Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 83197446 authored by FadhilP's avatar FadhilP
Browse files

add error handling in Topic get req

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