public void OnException(ExceptionContext context) { var json = new JsonErrorResponse(); if (context.Exception.GetType() == typeof(UserOperationException)) { json.Message = context.Exception.Message; context.Result = new BadRequestObjectResult(json); } else { json.Message = "发生了内部错误"; if (_env.IsDevelopment()) { json.DeveloperMessage = context.Exception.StackTrace; } context.Result = new InternalServerErrorObjectResult(json); } context.ExceptionHandled = true; }
public void OnException(ExceptionContext context) { var result = new JsonErrorResponse(); if (context.Exception.GetType() == typeof(UserOperationException)) { result.Message = context.Exception.Message; context.Result = new BadRequestObjectResult(result); } else { result.Message = "发生了未知的内部错误"; if (_env.IsDevelopment()) { result.DevelopMessage = context.Exception.ToString(); } context.Result = new InternalServerErrorObject(result); } _logger.LogError(context.Exception, context.Exception.Message); context.ExceptionHandled = true; }
public void OnException(ExceptionContext context) { var json = new JsonErrorResponse(); //自定义异常 if (context.Exception.GetType() == typeof(UserFriendlyException)) { json.Message = context.Exception.Message; context.Result = new BadRequestObjectResult(json); } else { json.Message = "500服务器内部错误"; if (_env.IsDevelopment()) { json.DeveloperMessage = context.Exception.StackTrace; } context.Result = new InternalServerErrorObjectResult(json); } _logger.LogError(context.Exception, context.Exception.Message); context.ExceptionHandled = true; }
public InternalServerErrorObject(JsonErrorResponse error) : base(error) { StatusCode = StatusCodes.Status500InternalServerError; }