28 lines
881 B
C#
28 lines
881 B
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LearnWordManage
|
|
{
|
|
class CustomExceptionFilter : IAsyncExceptionFilter
|
|
{
|
|
public async Task OnExceptionAsync(ExceptionContext context)
|
|
{
|
|
var result = new
|
|
{
|
|
Code = -1,
|
|
Message = context.Exception.Message,
|
|
StackTrace = context.Exception.StackTrace
|
|
};
|
|
context.Result = new JsonResult(result);
|
|
Console.WriteLine(context.Exception.Message );
|
|
Console.WriteLine( context.Exception.StackTrace);
|
|
context.ExceptionHandled = true;
|
|
}
|
|
}
|
|
}
|