[#2006] change to throw NacosException to make client handle the right Exception case

This commit is contained in:
huangyonghui 2019-11-04 15:38:25 +08:00
parent 68075458e2
commit 7956acbf64

View File

@ -429,16 +429,16 @@ public class NamingProxy {
+ result.code + " msg: " + result.content);
}
public String reqAPI(String api, Map<String, String> params, List<String> servers) {
public String reqAPI(String api, Map<String, String> params, List<String> servers) throws NacosException {
return reqAPI(api, params, servers, HttpMethod.GET);
}
public String reqAPI(String api, Map<String, String> params, List<String> servers, String method) {
public String reqAPI(String api, Map<String, String> params, List<String> servers, String method) throws NacosException {
params.put(CommonParams.NAMESPACE_ID, getNamespaceId());
if (CollectionUtils.isEmpty(servers) && StringUtils.isEmpty(nacosDomain)) {
throw new IllegalArgumentException("no server available");
throw new NacosException(NacosException.INVALID_PARAM, "no server available");
}
Exception exception = new Exception();
@ -463,7 +463,7 @@ public class NamingProxy {
index = (index + 1) % servers.size();
}
throw new IllegalStateException("failed to req API:" + api + " after all servers(" + servers + ") tried: "
throw new NacosException(NacosException.SERVER_ERROR, "failed to req API:" + api + " after all servers(" + servers + ") tried: "
+ exception.getMessage());
}
@ -476,7 +476,7 @@ public class NamingProxy {
}
}
throw new IllegalStateException("failed to req API:/api/" + api + " after all servers(" + servers + ") tried: "
throw new NacosException(NacosException.SERVER_ERROR, "failed to req API:/api/" + api + " after all servers(" + servers + ") tried: "
+ exception.getMessage());
}