コード例 #1
0
ファイル: EGException.cs プロジェクト: zero1036/TGNet
        /// <summary>
        /// 抛异常
        /// </summary>
        /// <typeparam name="Tx"></typeparam>
        /// <param name="strMessage"></param>
        /// <param name="pCode"></param>
        public static void ThrowX <Tx>(string strMessage, EGActionCode pCode)
            where Tx : Exception, new()
        {
            EGExceptionResult pResult = new EGExceptionResult();

            pResult.IsSuccess = false;
            pResult.Message   = strMessage;
            pResult.ExCode    = ((int)pCode).ToString();

            throw new EGException(strMessage, new Tx(), pResult);
        }
コード例 #2
0
ファイル: EGException.cs プロジェクト: zero1036/TGNet
        /// <summary>
        /// 抛异常
        /// </summary>
        /// <typeparam name="Tx"></typeparam>
        /// <param name="strMessage"></param>
        /// <param name="pCode"></param>
        public static void ThrowX <Tx>(string strMessage, string pCode)
            where Tx : Exception, new()
        {
            EGExceptionResult pResult = new EGExceptionResult();

            pResult.IsSuccess = false;
            pResult.Message   = strMessage;
            pResult.ExCode    = pCode;

            throw new EGException(strMessage, new Tx(), pResult);
        }
コード例 #3
0
ファイル: EGException.cs プロジェクト: zero1036/TGNet
        /// <summary>
        /// 转换异常为输出json实体
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static EGExceptionResult ConvertException(Exception ex)
        {
            EGExceptionResult ActionResult = new EGExceptionResult();

            //EG定制异常
            if (ex is EG.WeChat.Utility.Tools.EGException)
            {
                if ((ex as EG.WeChat.Utility.Tools.EGException) != null)
                {
                    ActionResult = (ex as EG.WeChat.Utility.Tools.EGException).JsonResult;
                }
            }
            //Senparc SDK报错异常
            else if (ex is Senparc.Weixin.Exceptions.ErrorJsonResultException)
            {
                if ((ex as Senparc.Weixin.Exceptions.ErrorJsonResultException) != null)
                {
                    ErrorJsonResultException pEx = (ex as Senparc.Weixin.Exceptions.ErrorJsonResultException);
                    ActionResult.Message   = pEx.JsonResult.errmsg;
                    ActionResult.IsSuccess = false;
                    var code = Enum.GetName(typeof(Senparc.Weixin.ReturnCode), pEx.JsonResult.errcode);
                    if (code == null)
                    {
                        ActionResult.ExCode = "9999";
                    }
                    else
                    {
                        ActionResult.ExCode = code.ToString();
                    }
                }
            }
            //其他异常,未来可在这扩展其他异常
            else
            {
                EGExceptionResult pResult = new EGExceptionResult();
                pResult.ExCode    = ((int)EGActionCode.未知错误).ToString();
                pResult.IsSuccess = false;
                pResult.Message   = ex.Message;

                ActionResult = pResult;
            }
            return(ActionResult);
        }
コード例 #4
0
ファイル: EGException.cs プロジェクト: zero1036/TGNet
 /// <summary>
 ///
 /// </summary>
 /// <param name="message"></param>
 /// <param name="inner"></param>
 /// <param name="jsonResult"></param>
 public EGException(string message, Exception inner, EGExceptionResult jsonResult)
     : base(message, inner)
 {
     JsonResult = jsonResult;
 }