mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-20 17:38:18 +02:00
Use new front-end based on Dashmin template
This commit is contained in:
parent
c118242c5b
commit
dbd7fafb34
4391 changed files with 228401 additions and 73494 deletions
51
UI/Middlewares/ErrorHandlingMiddleware.cs
Normal file
51
UI/Middlewares/ErrorHandlingMiddleware.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using MTWireGuard.Application;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MTWireGuard.Middlewares
|
||||
{
|
||||
public class ErrorHandlingMiddleware(RequestDelegate next)
|
||||
{
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await next(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await HandleExceptionAsync(context, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static Task HandleExceptionAsync(HttpContext context, Exception exception)
|
||||
{
|
||||
string exceptionType = exception.GetType().Name,
|
||||
message = exception.Message,
|
||||
stackTrace = exception.StackTrace,
|
||||
details = JsonConvert.SerializeObject(exception)!;
|
||||
|
||||
var viewResult = new ViewResult
|
||||
{
|
||||
ViewName = "Error",
|
||||
StatusCode = 500
|
||||
};
|
||||
viewResult.ViewData["Title"] = message;
|
||||
viewResult.ViewData["Message"] = stackTrace;
|
||||
viewResult.ViewData["Details"] = details;
|
||||
|
||||
var html = viewResult.ToHtml(context);
|
||||
|
||||
return context.Response.WriteAsync(html);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ExceptionHandlerMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseExceptionHandling(this IApplicationBuilder builder)
|
||||
{
|
||||
return builder.UseMiddleware<ErrorHandlingMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue