zoukankan      html  css  js  c++  java
  • WebApi异常过滤器

     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(@"
     
     在 line 1");
                m_strError = reg.Replace(m_strError, "");
                reg = new Regex(@"
    (.+)");
                m_strError = reg.Replace(m_strError, "");
                return m_strError;
            }
  • 相关阅读:
    【POJ1958】汉诺塔+
    hdu 5067(暴力搜索)
    hdu 5063(思路题-反向操作数组)
    hdu 5062(水题)
    hdu 2227(树状数组+dp)
    hdu 5480(维护前缀和+思路题)
    hdu 2492(树状数组)
    hdu 1394(树状数组)
    poj 2299(离散化+树状数组)
    poj 3321(树状数组)
  • 原文地址:https://www.cnblogs.com/wangjp-1233/p/13282287.html
Copyright © 2011-2022 走看看