Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Throw exceptions on non development enviroment Blazor

$
0
0

I have a Blazor Hosted WebAssembly app written on .NET8, so there are three projects Client, Server and the Shared. Intercommunication happends with Web API calls. In my razor components I have the following code to throw exceptions into a pop-up modal window:

The code in any function:

if (!response.IsSuccessStatusCode){    teamProcessing = false;    var responseContent = await response.Content.ReadAsStringAsync();    await ShowTheExceptionModal(responseContent);}

The exception function

protected async Task ShowTheExceptionModal(string message){    var options = new ModalOptions()    {        Size = ModalSize.Custom,        SizeCustomClass = "bm-modal-custom"    };    var parameters = new ModalParameters();    parameters.Add("message", message);    var messageForm = modal.Show<Message_Modal>("Exception Error", parameters, options);    var result = await messageForm.Result;}

The above works fine when ASPNETCORE_ENVIRONMENT is 'Development' but when ASPNETCORE_ENVIRONMENT is something else, the window opens but there is no message. I think this behaviour occurs due to that exceptions might provide sensitive information. I have also read that there is a middleware when ASPNETCORE_ENVIRONMENT is not 'Development' due to this code on Program.cs of the server.

if (app.Environment.IsDevelopment()){    app.UseWebAssemblyDebugging();}else{    app.UseExceptionHandler("/Error");    app.UseHsts();}

In my case I need to throw those exceptions and do not change the code on all functions within the application, is this possible somehow?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>