DEV Community

Discussion on: 10 Tips to Write Cleaner Vue.js Code

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
jacobandrewsky profile image
Jakub Andrzejewski

When using VueUse axios for example, you get a centralized approach to handle errors (the error property returned by the composable. This means that the composable handles the error returning to you the result that you can display to a user in a friendly way. And you don't need to write try/catch in every place to achieve that as it is handled by the composable.

If not using utility like the one above, you could create your own useApiClient composable that could be a wrapper around the fetch method that will also by default handle errors and populate a property to show you what the error code and message was.