enkodellc / blazorboilerplate

Blazor Boilerplate / Starter Template with MudBlazor
MIT License
1.87k stars 371 forks source link

Useful tip for troubleshooting HTTP/API response problems; would be good to document somewhere #973

Open RajNZ opened 1 year ago

RajNZ commented 1 year ago

The file APIResponseRequestLoggingMiddleware.cs interrupts HTTP communications to log API calls; with some exceptions based on the URL path it wraps any response received and this is important to know because if you introduce any 3rd party system from which you are receiving a response that must remain untampered with then you must add the partial path of that system to the list of exceptions.

My example is adding Bold Reports by Syncfusion - after much troubleshooting by them and I we discovered that the JSON response being sent back from the report server wasn't working properly and it is the middleware interruption that causes the problem. After adding their API path to the exception list things started working!

wint100 commented 1 year ago

I'm having issues with Syncfusion Datagrid as well. When editing a Todo item with their grid, the Grid hangs and the Middleware throws a StackOverflow exception and I'm struggling to pin it down. The path at the time of exception is /_blazor. I'm hoping this is a similar issue and there's a quick fix but so far I'm failing to find the cause.

wint100 commented 1 year ago

This is where it fails for me: image

RajNZ commented 1 year ago

I don't know the answer, but I suggest you add another exception to the StartsWithSegments check on the previous line. This will allow the code in the next block to execute instead... ...

if (new string[] { "/api/localization", "/api/data", "/api/externalauth" }.Any(e => request.Path.StartsWithSegments(new PathString(e.ToLower()))))
                            await _next.Invoke(httpContext);

Then add the same exception again to the StartsWithSegments check here - maybe calling _next.Invoke() here is better than simply _next() done earlier?