Пример #1
0
 /// <summary>
 /// 生成错误回应字符串
 /// </summary>
 /// <param name="type">错误类型</param>
 /// <returns>错误回应字符串</returns>
 public static string GenError(MornErrorType type)
 {
     return(JsonConvert.SerializeObject(new Dictionary <string, object>()
     {
         { MornConstants.ERROR_CODE, MornErrorUtil.GetErrorCode(type) },
         { MornConstants.ERROR_MESSAGE, MornErrorUtil.GetDescription(type) },
     }));
 }
Пример #2
0
 public static string GenError(MornErrorType type, string addition)
 {
     if (string.IsNullOrEmpty(addition))
     {
         return(GenError(type));
     }
     else
     {
         return(JsonConvert.SerializeObject(new Dictionary <string, object>()
         {
             { MornConstants.ERROR_CODE, GetErrorCode(type) },
             { MornConstants.ERROR_MESSAGE, string.Format("{0} : {1}", GetDescription(type), addition) },
         }));
     }
 }
Пример #3
0
        private T CreateErrorResponse <T>(MornErrorType type, string addition) where T : MornResponse
        {
            var rsp = Activator.CreateInstance <T>();

            rsp.ErrorCode = MornErrorUtil.GetErrorCode(type);
            if (string.IsNullOrEmpty(addition))
            {
                rsp.ErrorMessage = MornErrorUtil.GetDescription(type);
            }
            else
            {
                rsp.ErrorMessage = string.Format("{0} : {1}", MornErrorUtil.GetDescription(type), addition);
            }
            return(rsp);
        }
Пример #4
0
        public static string GetDescription(MornErrorType type)
        {
            string r;

            return(_errors.TryGetValue(type, out r) ? r : "未知错误");
        }
Пример #5
0
 public static string GetErrorCode(MornErrorType type)
 {
     return(((int)type).ToString());
 }
Пример #6
0
 public MornException(MornErrorType type, string message)
     : base(message)
 {
     ErrorType = type;
 }
Пример #7
0
 public MornException(MornErrorType type)
     : base()
 {
     ErrorType = type;
 }