Design comparison
SolutionDesign
Solution retrospective
Hey!
This app is the beginning of my TS journey and I hope you like it.
As this API tends to have bugs with random data, I just added ID of hint as parameter and generated it myself. 😀
Community feedback
- @cancomertpayPosted 12 months ago
Hey Jacob, great work! But, when you send a random number between 1 and 224, if it happens to be 67, you encounter an error because the API isn't perfect. You could try using the 'do while' method like this :
do { let randomNumber = Math.floor(Math.random() * 224) + 1; const response = await fetch( `https://api.adviceslip.com/advice/${randomNumber}` ); if (response.ok) { const result = await response.json(); if (result?.message?.type !== "error") { setAdvice(result); break; } } else { throw new Error("Something went wrong, please refresh the page"); break; } } while (true);
Marked as helpful0@JJacobPRPosted 12 months agoHey thanks for notifying me about this!
I will fix this. I guess that's what happens when you try to fix API call without seeing its source code 😂
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