123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using System;
- using WMS.Info;
- namespace WMS.Core
- {
- public class SysExCore : Exception
- {
- /// <summary>
- /// 异常消息
- /// </summary>
- public string ExMsg { get; private set; }
- /// <summary>
- /// 内部异常
- /// </summary>
- public Exception Ex { get; private set; }
- /// <summary>
- /// 消息类型
- /// </summary>
- public ESysExType SysExType { get; private set; } = ESysExType.Exception;
- //带有一个字符串参数和一个内部异常信息参数的构造函数
- public SysExCore(ESysExType sysExType, string exMsg, Exception innerException) : base(exMsg, innerException)
- {
- Ex = innerException;
- ExMsg = exMsg;
- SysExType = sysExType;
- }
- public SysExCore(ESysExType sysExType, string exMsg) : base(exMsg)
- {
- ExMsg = exMsg;
- SysExType = sysExType;
- }
- /// <summary>
- /// 错误提示信息
- /// </summary>
- public static SysExCore ThrowFailException(string exMsg)
- {
- return new SysExCore(ESysExType.Fail, exMsg);
- }
- /// <summary>
- /// 错误提示信息
- /// </summary>
- public static SysExCore ThrowInEmpty()
- {
- return new SysExCore(ESysExType.Fail, "请求数据为空。");
- }
- /// <summary>
- /// token无效
- /// </summary>
- public static SysExCore ThrowToken()
- {
- return new SysExCore(ESysExType.LoginTimeout, "当前登录token无效,请重新登录后再操作。");
- }
- /// <summary>
- /// 登录超时
- /// </summary>
- public static SysExCore ThrowLoginTimeout()
- {
- return new SysExCore(ESysExType.LoginTimeout, "登录超时,请重新登录!");
- }
- /// <summary>
- /// 密码过期
- /// </summary>
- public static SysExCore ThrowPwdExpiration()
- {
- return new SysExCore(ESysExType.PwdExpiration, "用户密码已过期。");
- }
- /// <summary>
- /// 数据库连接配置文件异常
- /// </summary>
- public static SysExCore ThrowDbSetError()
- {
- return new SysExCore(ESysExType.DbSetError, "数据库连接配置文件异常,请联系管理员。");
- }
- /// <summary>
- /// 数据库连接配置文件异常
- /// </summary>
- public static SysExCore ThrowDbConnError(Exception ex)
- {
- return new SysExCore(ESysExType.DbConnError, ex.Message, ex);
- }
- public static SysExCore GetSysExCore(Exception ex)
- {
- if (ex is SysExCore)
- {
- return ex as SysExCore;
- }
- else
- {
- return new SysExCore(ESysExType.Exception, ex.Message, ex);
- }
- }
- public static ResInfo GetResErr(Exception ex, object data = null)
- {
- SysExCore ec;
- if (ex is SysExCore)
- {
- ec = ex as SysExCore;
- }
- else
- {
- ec = new SysExCore(ESysExType.Exception, ex.Message, ex);
- }
- EResponseCode rescode = EResponseCode.Fail;
- if (ec.SysExType == ESysExType.Exception)
- {
- rescode = EResponseCode.Exception;
- }
- else if (ec.SysExType == ESysExType.LoginTimeout)
- {
- rescode = EResponseCode.LoginTimeout;
- }
- else if (ec.SysExType == ESysExType.PwdExpiration)
- {
- rescode = EResponseCode.PwdExpiration;
- }
- else if (ec.SysExType == ESysExType.PwdInit)
- {
- rescode = EResponseCode.PwdInit;
- }
- else if (ec.SysExType == ESysExType.FilterIPError)
- {
- rescode = EResponseCode.FilterIPError;
- }
- else if (ec.SysExType == ESysExType.FilterTimeError)
- {
- rescode = EResponseCode.FilterTimeError;
- }
- ResInfo infos = new ResInfo();
- infos.code = rescode;
- infos.info = ex.Message;
- infos.data = data;
- return infos;
- //return new ResInfo() { code = rescode, info = ex.Message, data = data };
- }
- public static ResInfo GetResSucc(string Msg="", object data = null)
- {
- return new ResInfo() { code = EResponseCode.Success, data = data, info = string.IsNullOrWhiteSpace(Msg) ? "响应成功" : Msg };
- }
- }
- }
|