2024-10-02 12:35:39 +08:00

56 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Mirai.Net.Sessions.Http.Managers;
public class MyExceptionFilter : IAsyncExceptionFilter
{
private readonly ILogger<MyExceptionFilter> logger;
private readonly IHostEnvironment env;
public MyExceptionFilter(ILogger<MyExceptionFilter> logger, IHostEnvironment env)
{
this.logger = logger;
this.env = env;
}
public Task OnExceptionAsync(ExceptionContext context)
{
Exception exception = context.Exception;
logger.LogError(exception, "UnhandledException occured");
ObjectResult result = new ObjectResult(new { code = 500, message = exception.Message });
try
{
MessageManager.SendGroupMessageAsync("860395385", $"<拉花实验室-错误>\r\n警告等级不严重\r\n内容{exception.Message}");
}
catch
{
}
result.StatusCode = 500;
context.Result = result;
context.ExceptionHandled = true;
return Task.CompletedTask;
}
}
public class code_st
{
public string message { get; set; }
public int status { get; set; }
}
public class error_mb
{
public int code { get; set; }
public string message { get; set; }
}