We use Blazor Server app for our UI which calls APIs for almost all functions. When an API responds with an error code, what is the best way to show this response and not make the app break the circuit and become unresponsive.
what is the best way to show this response and not make the app break the circuit and become unresponsive.
If you follow the standard HttpClient pattern then your code should not become unresponsive.
The community cannot see how your code is designed and you have not explained what you expect to happen when status other than 200 (ok) is returned. With that being said, a standard service pattern is typical. Then you get to write a custom implementation for Web API calls. The actual approach depends on your use case which is to vague at this point.
We use Service pattern to wrap all Web API calls. We also ensure that these are trapped in the try...catch block. However, when an endpoint responds with an Error status code, should we have State properties that are updated based on the response and follow the standard "BroadcastStateChange()" which we can then show in the UI somehow?
I wondered if there is another elegant way for this.