forked from ddrilling/AsbCloudServer
fd74ae20a0
Add exception handle middleware. Move middlawares into separate files.
36 lines
991 B
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|