java对枚举类型进⾏⾃动化匹配package ption;
import xception.IErrorCode;
/**
* @ClassName: ShellUtilError
* @Description:
* @Author: Datasure008
* @Date: 2021/9/8 11:21
*/
public enum ShellUtilError implements IErrorCode {
/**
*  * 200 不到paramiko模块,⽆法执⾏远程传输
*    * 201 不到配置⽂件(json)
*    * 202 配置⽂件(json)解析失败
*    * 203 参数⽆效
parse error怎么解决*    * 204 连接失败
*    * 205 没有到可⽤的安装包(linux_client_common_install.zip)
*    * 206 解压客户端安装包失败!
*    * 207 推送客户端安装包失败(蓝⾊表⽰win新增)WINDOWS特有
*    * 209 密码错误
*
*    * 101 检测到已安装,请先卸载
*    * 102 安装包不完整,缺少必要的⽂件
*    * 103 安装驱动失败!
*    * 104 添加DS引导项失败!
*    * 105 安装客户端程序失败!
*    * 106 ⽆法获取客户端代理程序包
*    * 110 当前系统不⽀持安装/卸载
*    * 111 参数解析错误
*    *
*    *
*    * 0 执⾏成功
*/
SUCCESS("110000","成功"),
NOT_FOUND_PARAMIKO_MODULE_ERROR("110200","paramiko模块,⽆法执⾏远程传输"),
NOT_FOUND_CONF_FILE_ERROR("110201","不到配置⽂件(json)"),
JSON_PARSE_ERROR("110202","配置⽂件(json)解析失败"),
PARAM_NOTEFFECT_ERROR("110203","参数⽆效"),
LINK_FAILED_ERROR("110204","连接失败"),
NOT_FOUND_INSTALL_PACKAGE_ERROR("110205","没有到可⽤的安装包(linux_client_common_install.zip)"),    UNZIP_ERROR("110206","解压客户端安装包失败!"),
PASSWORD_ERROR("110209","推送客户端安装包失败 !"),
HAVE_INSTALLED_ERROR("110101","检测到已安装,请先卸载"),
FILE_NOT_FILL_ERROR("110102","安装包不完整,缺少必要的⽂件"),
INSTALL_DERVER_FAIL_ERROR("110103","安装驱动失败!"),
DS_FILL_FAIL_ERROR("110104","添加DS引导项失败!"),
INSTALL_CLIENT_FAIL_ERROR("110105","安装客户端程序失败!"),
PROXY_PACKAGE_FAIL_ERROR("110106","法获取客户端代理程序包"),
LINUX_PROXY_PACKAGE_FAIL_ERROR("110107","执⾏远程命令失败"),
NOT_SUPPORT_INSTALL_OR_UNINSTALL_ERROR("110110","当前系统不⽀持安装/卸载"),
PARAM_PARSE_ERROR("110111","参数解析错误"),
WINDOWS_PUSH_PACKAGE_FAIL_ERROR("110207","下载安装包失败"),
;
private String errorCode;
private String errorMessage;
ShellUtilError(String errorCode, String errorMessage) {
}
}
@Override
public String getErrorCode() {
Code;
}
@Override
public String getErrorMessage() {
Message;
}
}
/**
* auth:jiaozongguan
* 处理各种异常
*/
ShellUtilError[] shellUtilErrors = ShellUtilError.values();
List<ShellUtilError> shellUtilErrorList = new ArrayList<>();
shellUtilErrorList = Arrays.asList(shellUtilErrors);
int finalExitCode = exitCode;
ShellUtilError shellUtilError = shellUtilErrorList.stream().filter(
m -> m.getErrorCode().substring(3, 6).equals(String.valueOf(finalExitCode))).findFirst().get();                // complete failed.
if (shellUtilError != null) {
throw new WebsocketException(shellUtilError);
}
package xception;
/**
* @ClassName: WebsocketException
* @Description:websocket消息异常,统⼀处理
* @Author: jiaozongguan
* @Date: 2021/8/10 14:04
*/
public class WebsocketException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* 错误码
*/
protected String errorCode;
/**
* 错误信息
*/
protected String errorMessage;
public WebsocketException() {
super();
}
public WebsocketException(IErrorCode errorCode) {
ErrorMessage());
}
public WebsocketException(IErrorCode errorCode, Throwable cause) {
public WebsocketException(IErrorCode errorCode, Throwable cause) {
ErrorMessage(), cause);
}
public WebsocketException(String errorMsg) {
super(errorMsg);
}
public WebsocketException(String errorCode, String errorMsg) {
super(errorMsg);
}
public WebsocketException(String errorCode, String errorMsg, Throwable cause) {        super(errorMsg, cause);
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
}
public String getMessage() {
return errorMessage;
}
@Override
public Throwable fillInStackTrace() {
return this;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。