Ejemplo n.º 1
0
        /// <summary>
        /// 异常处理
        /// </summary>
        /// <param name="app"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseCustomException(this IApplicationBuilder app, Action <CustomExceptionMiddleWareOption> action)
        {
            CustomExceptionMiddleWareOption customExceptionMiddleWareOption = new CustomExceptionMiddleWareOption();

            action(customExceptionMiddleWareOption);
            return(app.UseMiddleware <CustomExceptionMiddleWare>(customExceptionMiddleWareOption));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="next"></param>
 /// <param name="option"></param>
 public CustomExceptionMiddleWare(RequestDelegate next,
                                  CustomExceptionMiddleWareOption option,
                                  IJsonSerializerService jsonSerializerService,
                                  ILogger <CustomExceptionMiddleWare> logger)
 {
     _next   = next;
     _option = option;
     exceptionStatusCodeDic = new Dictionary <int, string>
     {
         { 401, "未授权的请求" },
         { 404, "找不到该页面" },
         { 403, "访问被拒绝" },
         { 500, "服务器发生意外的错误" }
         //其余状态自行扩展
     };
     _jsonSerializerService = jsonSerializerService;
     _logger = logger;
 }