首页 > Windows开发 > 详细

WebApi异常过滤器

时间:2020-07-11 09:47:03      阅读:56      评论:0      收藏:0      [点我收藏+]
 public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            var x = actionExecutedContext.Exception;
            Trace.TraceError(x.ToString());
            actionExecutedContext.Response = new HttpResponseMessage(HttpStatusCode.OK);
            actionExecutedContext.Response.Content = new ObjectContent<ApiResult>(ApiResult.ret((int)ApiResult.enum_result.fail, filter(x.Message), null), new System.Net.Http.Formatting.JsonMediaTypeFormatter());

        }
private string filter(string m_strError)
        {
            if (string.IsNullOrEmpty(m_strError) || m_strError.ToLower().Equals("null"))
                return string.Empty;
            Regex reg = new Regex("ORA-(.+):");
            m_strError = reg.Replace(m_strError, "");
            reg = new Regex("at(.+)");
            m_strError = reg.Replace(m_strError, "");
            reg = new Regex("在 \"I~H~M~S2014_TG_LOGIN(.+)");
            m_strError = reg.Replace(m_strError, "");
            reg = new Regex("在 \"line(.+)");
            m_strError = reg.Replace(m_strError, "");
            reg = new Regex(@"\n \n 在 line 1");
            m_strError = reg.Replace(m_strError, "");
            reg = new Regex(@"\n(.+)");
            m_strError = reg.Replace(m_strError, "");
            return m_strError;
        }

 

WebApi异常过滤器

原文:https://www.cnblogs.com/wangjp-1233/p/13282287.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!