fix vali middleware
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Lib.Core.MiddlewareExtension
|
||||
{
|
||||
public class ExceptionHandlingMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IExceptionHandler _exceptionHandler;
|
||||
|
||||
public ExceptionHandlingMiddleware(RequestDelegate next, IExceptionHandler exceptionHandler)
|
||||
{
|
||||
_next = next;
|
||||
_exceptionHandler = exceptionHandler;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context, ILogger<ExceptionHandlingMiddleware> logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _next(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogDebug(ex, "ExceptionHandlingMiddleware");
|
||||
|
||||
await _exceptionHandler.ExceptionHandle(context, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
|
||||
namespace Lib.Core.MiddlewareExtension.Extension
|
||||
{
|
||||
public static class MiddlewareExtension
|
||||
{
|
||||
public static IApplicationBuilder UseMiddlewareExtension(this IApplicationBuilder app, IExceptionHandler exceptionHandler)
|
||||
{
|
||||
app.UseMiddleware<ExceptionHandlingMiddleware>(exceptionHandler);
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Lib.Core.MiddlewareExtension
|
||||
{
|
||||
public interface IExceptionHandler
|
||||
{
|
||||
Task ExceptionHandle(HttpContext context, Exception exception);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user