From 7956acbf64b98d0b29d62cfc565aba80a84b0873 Mon Sep 17 00:00:00 2001 From: huangyonghui Date: Mon, 4 Nov 2019 15:38:25 +0800 Subject: [PATCH] [#2006] change to throw NacosException to make client handle the right Exception case --- .../alibaba/nacos/client/naming/net/NamingProxy.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/net/NamingProxy.java b/client/src/main/java/com/alibaba/nacos/client/naming/net/NamingProxy.java index d52c48486..186d88069 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/net/NamingProxy.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/net/NamingProxy.java @@ -429,16 +429,16 @@ public class NamingProxy { + result.code + " msg: " + result.content); } - public String reqAPI(String api, Map params, List servers) { + public String reqAPI(String api, Map params, List servers) throws NacosException { return reqAPI(api, params, servers, HttpMethod.GET); } - public String reqAPI(String api, Map params, List servers, String method) { + public String reqAPI(String api, Map params, List 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()); }