0

I have an ASP.NET Core 6.0 Web API. One of the middleware catches an exception and translates it to a user-friendly error message as response.

This is existing web API and multiple middleware are added and changes by multiple developer, I am not sure which middleware is causing problem to share minimal reproducible example. when API response is 200 there is no issue. Only when response is != 200, client will continuously wait for response and in Application Insight Request table (logged by custom middleware) there are multiple rows created for same request values. Below code form middleware is only one, i can think of causing issue.

Looking for help in understanding if there is any config/feature in ASP.NET which internally can retrigger new request in case of errors Or if there is any Http status (like http redirection) which API might be sending which might be making client to send another request. Or any suggestion on how to debug/troubleshoot it.

app.UseMiddleware(middlewareA);
app.UseMiddleware(middlewareB);

//middlewareB is implemented as
public async Task Invoke(HttpContext context)
{
    try
    {
       //call next middleware
    }
    catch(Exception ex)
    {
      context.Response.StatusCode = 404;
      context.Response.WriteAsync("custom error message");
    }
}
4
  • You need to provide a minimal reproducible example. Commented Aug 3, 2023 at 12:48
  • Could you please explain a bit more about the scenario or in which condition its looping over and over again? Can you share that relevant part in order to simulate your issue? Commented Aug 4, 2023 at 5:13
  • updated question with few clarifications. Commented Aug 4, 2023 at 22:07
  • Well, when !=200 then did you had the chance to check which middleware is executing of this app.UseMiddleware(middlewareA); app.UseMiddleware(middlewareB); you can check the application log in order to know the details exactly which middleware causing the issue. Commented Aug 11, 2023 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.