question

RonaldRex-2335 avatar image
0 Votes"
RonaldRex-2335 asked ZhiLv-MSFT commented

Error Handling In Blazor Web Server Application

I am calling a web API endpoint from my Blazor server application. And I intentionally have not started the application (.Net Core 6 Web Api) with the api service. Meaning, there is no service listening on the specified port. And I was wondering what is the best practice for handling this error. I am assuming it will be handled on the server hosting the api service which will send a message back to my blazor application? Thanks !!! Actually I just thought of something. How can my service return an error message if its not running. So I would have to code for this exception on the client or blazor server end?


226507-blazer-server-app-code.png


226523-net-core-6-web-api-code.png


dotnet-aspnet-core-blazordotnet-aspnet-webapi
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RonaldRex-2335,

Refer to the Handle errors in ASP.NET Core Blazor apps, When an error occurs, Blazor apps display a light yellow bar at the bottom of the screen:

During development, the bar directs you to the browser console, where you can see the exception.
In production, the bar notifies the user that an error has occurred and recommends refreshing the browser.

In the OnInitializedAsync method, you can also use a try-catch statement with error handling and logging.

Best regards,
Dillion

1 Vote 1 ·

0 Answers