REST Countries API w/ Svelkit, Ts, Tailwind, Axios & SSR prefetching

Solution retrospective
It was a great project to practice dynamic routes in Sveltkit.
But i could not find the way to catch the API call errors on the client side.
Maybe you know how ? 😊
I would also like to implement a caching system (maybe service worker ??) for already fetched endpoints.
If you have any advice or resources on that matter or anything about the layout or the code feel free to share.
Have a nice day/night. Peace
Please log in to post a comment
Log in with GitHubCommunity feedback
- @fadhilradh
Hi Antoinec,
Your project is good and works as expected.
Regarding your question about :
But i could not find the way to catch the API call errors on the client side.
I read your code, in the
requests.config.ts
, you need to passerror
as catch parameter, then pass theerror
again in yourthrow
.So, insted of writing this in your code :
catch (_) { throw new Error("Sorry! We could not access the API."); }
You should write like so :
catch (error) { throw new Error(`Sorry! We could not access the API because ${error}`); }
Hope it helps and good luck!
Join 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