DD.WellWorkover.Cloud/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs
Фролов fd74ae20a0 CS2-117, CS2-112
Add exception handle middleware.
Move middlawares into separate files.
2021-11-10 17:04:07 +05:00

36 lines
991 B
C#

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;
}
}
}
}