40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
| using IRaCIS.Core.Infrastructure.Extention;
 | ||
| using Microsoft.AspNetCore.Mvc;
 | ||
| using Panda.DynamicWebApi.Attributes;
 | ||
| 
 | ||
| namespace EasyCaching.Demo.Interceptors.Controllers
 | ||
| {
 | ||
| 
 | ||
|     [NonDynamicWebApi]
 | ||
|     public class ErrorController : ControllerBase
 | ||
|     {
 | ||
|         /// <summary>
 | ||
|         /// 主要处理 前端404等错误  全局业务异常已统一处理了,非业务错误会来到这里
 | ||
|         /// </summary>
 | ||
|         /// <param name="code"></param>
 | ||
|         /// <returns></returns>
 | ||
|         [Route("error/{code:int}")]
 | ||
|         [HttpGet]
 | ||
|         public IResponseOutput Error(int code)
 | ||
|         {
 | ||
| 
 | ||
|             if (code < 500)
 | ||
|             {
 | ||
|                 //LogDashboard 要求返回码必须是401不能覆盖,否则 认证有问题
 | ||
|                 if (code == 401)
 | ||
|                 {
 | ||
|                     ControllerContext.HttpContext.Response.StatusCode = 401;
 | ||
|                 }
 | ||
| 
 | ||
|                 return ResponseOutput.NotOk($"Client error, actual request error status code({code})");
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
| 
 | ||
|                 return ResponseOutput.NotOk($"Server error , actual request error status code({code})");
 | ||
|             }
 | ||
| 
 | ||
|         }
 | ||
|     }
 | ||
| }
 |