I'm building an internal tool using Blazor WASM and dotnet6, which makes calls to external APIs.
Minimalistic example in Xunit - but imagine this is running from a Blazor client
[Xunit.Theory]
[InlineData("http://www.brokenexample.com/", "blocked for mixed-content")]
[InlineData("https://www.brokenexample.com/", "ERR_NAME_NOT_RESOLVED")]
[InlineData("https://www.api.with.cors.com/", "CORS Error")]
public async Task CanGetErrorMessage(string url, string expectedError)
{
try
{
var httpClient = new HttpClient();
var httpResponseMessage = await httpClient.GetAsync(url);
}
catch (Exception e)
{
var innerError = e.Message; // somehow find the inner error
Assert.Equal(innerError, expectedError);
}
}
Screenshot of "blocked for mixed content" in chrome network tab:

Screenshot of ERR_NAME_NOT_RESOLVED in chrome network tab:

Screenshot of CORS Error in chrome network tab:

However, my e.Message is always
"TypeError: Failed to fetch"
And the inner exception is always
System.Runtime.InteropServices.JavaScript.JSException
With the same error message, and no further inner exception
So I'm guessing Blazor is Interopping with Javascript, which throws an exception at it - Maybe the Interop/Proxy client is catching it and just returning "TypeError: Failed to fetch"
Somehow my (chrome) browser is able to distinguish between different kind of connection errors, but the "real" exception doesn't seems to appear anywhere in my exception stack.
Sometimes there's an Http-Statuscode that is somewhat useful, but anything that fails pre-flight like CORS or connection refused seems all the same
The purpose of this tool is that a user can input their URL during runtime and test the connection, so I can't really predetermine what will happen, and if the connection will work.
It's an internal tool, so I'd like to be able to tell my end-user something like "This url didn't work because of CORS, you can fix that by downloading a chrome extension to disable cors, etc etc. And more in detailed explanation why a certain url doesn't work, and assist them into getting it to work
Any way to get the status information as shown in these screenshots?
