/// <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) }, })); }
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) }, })); } }
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); }
public static string GetDescription(MornErrorType type) { string r; return(_errors.TryGetValue(type, out r) ? r : "未知错误"); }
public static string GetErrorCode(MornErrorType type) { return(((int)type).ToString()); }
public MornException(MornErrorType type, string message) : base(message) { ErrorType = type; }
public MornException(MornErrorType type) : base() { ErrorType = type; }