using Microsoft.AspNetCore.Http; using System; using System.Threading.Tasks; namespace AsbCloudWebApi.Middlewares { public class SimplifyExceptionsMiddleware { private readonly RequestDelegate next; public SimplifyExceptionsMiddleware(RequestDelegate next) { this.next = next; } public async Task InvokeAsync(HttpContext context) { try { await next?.Invoke(context); } catch (TaskCanceledException ex) { Console.WriteLine(ex.Message); } catch(Exception ex) { if (ex.Message.Contains("Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate.")) Console.WriteLine("Reading the request body timed out due to data arriving too slowly."); else throw; } } } }