commit
57b0fe3b52
@ -42,7 +42,7 @@ public class ConfigFactory {
|
||||
ConfigService vendorImpl = (ConfigService) constructor.newInstance(properties);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(-400, e.getMessage());
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.alibaba.nacos.api.exception;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* Nacos Exception
|
||||
*
|
||||
@ -31,6 +34,8 @@ public class NacosException extends Exception {
|
||||
|
||||
private String errMsg;
|
||||
|
||||
private Throwable causeThrowable;
|
||||
|
||||
public NacosException() {
|
||||
}
|
||||
|
||||
@ -40,12 +45,31 @@ public class NacosException extends Exception {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public NacosException(int errCode, Throwable throwable) {
|
||||
super(throwable);
|
||||
this.errCode = errCode;
|
||||
setCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
public NacosException(int errCode, String errMsg, Throwable throwable) {
|
||||
super(errMsg, throwable);
|
||||
this.errCode = errCode;
|
||||
this.errMsg = errMsg;
|
||||
setCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
public int getErrCode() {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
public String getErrMsg() {
|
||||
return errMsg;
|
||||
if (!StringUtils.isBlank(this.errMsg)) {
|
||||
return errMsg;
|
||||
}
|
||||
if (this.causeThrowable != null) {
|
||||
return causeThrowable.getMessage();
|
||||
}
|
||||
return Constants.NULL;
|
||||
}
|
||||
|
||||
public void setErrCode(int errCode) {
|
||||
@ -56,9 +80,20 @@ public class NacosException extends Exception {
|
||||
this.errMsg = errMsg;
|
||||
}
|
||||
|
||||
public void setCauseThrowable(Throwable throwable) {
|
||||
this.causeThrowable = getCauseThrowable(throwable);
|
||||
}
|
||||
|
||||
private Throwable getCauseThrowable(Throwable t) {
|
||||
if (t.getCause() == null) {
|
||||
return t;
|
||||
}
|
||||
return getCauseThrowable(t.getCause());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ErrCode:" + errCode + ",ErrMsg:" + errMsg;
|
||||
return "ErrCode:" + getErrCode() + ", ErrMsg:" + getErrMsg();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ public class NamingFactory {
|
||||
NamingService vendorImpl = (NamingService)constructor.newInstance(serverList);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(-400, e.getMessage());
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ public class NamingFactory {
|
||||
NamingService vendorImpl = (NamingService)constructor.newInstance(properties);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(-400, e.getMessage());
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class NamingMaintainFactory {
|
||||
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(serverList);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(-400, e.getMessage());
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ public class NamingMaintainFactory {
|
||||
NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(properties);
|
||||
return vendorImpl;
|
||||
} catch (Throwable e) {
|
||||
throw new NacosException(-400, e.getMessage());
|
||||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ public class ClientWorker {
|
||||
"[%s] [sub-server] get server config exception, dataId=%s, group=%s, tenant=%s", agent.getName(),
|
||||
dataId, group, tenant);
|
||||
LOGGER.error(message, e);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, e.getMessage());
|
||||
throw new NacosException(NacosException.SERVER_ERROR, e);
|
||||
}
|
||||
|
||||
switch (result.code) {
|
||||
|
@ -51,7 +51,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
|
||||
raftCore.signalPublish(key, value);
|
||||
} catch (Exception e) {
|
||||
Loggers.RAFT.error("Raft put failed.", e);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft put failed, key:" + key + ", value:" + value);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft put failed, key:" + key + ", value:" + value, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
|
||||
raftCore.unlistenAll(key);
|
||||
} catch (Exception e) {
|
||||
Loggers.RAFT.error("Raft remove failed.", e);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft remove failed, key:" + key);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft remove failed, key:" + key, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
|
||||
raftCore.onPublish(datum, source);
|
||||
} catch (Exception e) {
|
||||
Loggers.RAFT.error("Raft onPut failed.", e);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft onPut failed, datum:" + datum + ", source: " + source);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft onPut failed, datum:" + datum + ", source: " + source, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService
|
||||
raftCore.onDelete(datum.key, source);
|
||||
} catch (Exception e) {
|
||||
Loggers.RAFT.error("Raft onRemove failed.", e);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft onRemove failed, datum:" + datum + ", source: " + source);
|
||||
throw new NacosException(NacosException.SERVER_ERROR, "Raft onRemove failed, datum:" + datum + ", source: " + source, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user