Handling Errors in Blazor WebAssembly
You are working hard on the client side, you have built an amazing app that does everything perfectly, the UI is great, your app is fetching and sending data from and to the API correctly, and everyone is happy. But what if the API, for some reason, is taking too long to process requests, so your app loads for around 30 seconds, then a yellow bar appears at the bottom, indicating that an unhandled exception occurred? That’s an experience that neither the user nor the developer would like to have.
Errors and exceptions can occur for many reasons and in many parts of an app. The goal of this chapter is to learn the techniques to handle them properly and give users a better experience. We will start by explaining why error handling matters and then how to manage the errors that could arise from communication with the API. Then, we will build a global error handler, where all errors will be handled and processed properly. Finally, we will...