Handling errors in our recipe app
The first thing we are going to do is stop our mock service. Yes, you heard it right; stop it. This way, the call to the getRecipes
service will fail because the server is down.
Now, if you refresh the front app, you will see that nothing, including our list of recipes, is displayed. Why do we get this behavior? Because we did not handle the errors. The error was thrown, the stream was completed, and nothing happened afterward. We have a white screen where nothing is displayed.
Now open the console, and you will see the failed request:
Figure 4.5 – The console showing the failed request
A failing HTTP request would never have broken our app if it was handled correctly. That’s why you should be very careful when raising HTTP requests in your front application.
So, how can we fix this? Which strategy that we’ve previously discussed will fit the best?
If we choose the...