Design comparison
SolutionDesign
Solution retrospective
Questions:
- How can I catch it if the api call doesn't find a user with that name?
- Do you like the way I implemented responsive design?
- I have been struggling with using global state, is Zustand a good package for this?
Community feedback
- @fazzaamiarsoPosted over 2 years ago
Hello Clytax! Nice solution!
The easiest way to handle the error is by throwing an exception on the response and appending
.catch
on your promise chain. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch.then(res => { if(!res.ok) throw Error('Failed to fetch'); //exception; return res.json(); }).then().then().catch(error => console.log(error.message) )
I also recommend you to read this article to answer your state question https://kentcdodds.com/blog/application-state-management-with-react
I hope it helps! Cheers!
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord