From c4ad0888e04e4925f15e604b0404bcc7f7cbae64 Mon Sep 17 00:00:00 2001 From: nkorange Date: Wed, 6 Mar 2019 11:59:15 +0800 Subject: [PATCH] #869 Clarify exception message --- .../nacos/api/exception/NacosException.java | 1 + .../nacos/client/naming/net/NamingProxy.java | 24 +++++-------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/com/alibaba/nacos/api/exception/NacosException.java b/api/src/main/java/com/alibaba/nacos/api/exception/NacosException.java index 1bbd56dc9..aab756e60 100644 --- a/api/src/main/java/com/alibaba/nacos/api/exception/NacosException.java +++ b/api/src/main/java/com/alibaba/nacos/api/exception/NacosException.java @@ -35,6 +35,7 @@ public class NacosException extends Exception { } public NacosException(int errCode, String errMsg) { + super(errMsg); this.errCode = errCode; this.errMsg = errMsg; } 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 e27ff5088..2f14dc127 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 @@ -18,7 +18,6 @@ package com.alibaba.nacos.client.naming.net; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; -import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.CommonParams; import com.alibaba.nacos.api.naming.pojo.Instance; @@ -28,23 +27,14 @@ import com.alibaba.nacos.api.selector.ExpressionSelector; import com.alibaba.nacos.api.selector.SelectorType; import com.alibaba.nacos.client.monitor.MetricsMonitor; import com.alibaba.nacos.client.naming.beat.BeatInfo; -import com.alibaba.nacos.client.naming.utils.CollectionUtils; -import com.alibaba.nacos.client.naming.utils.IoUtils; -import com.alibaba.nacos.client.naming.utils.NetUtils; -import com.alibaba.nacos.client.naming.utils.StringUtils; -import com.alibaba.nacos.client.naming.utils.UtilAndComs; +import com.alibaba.nacos.client.naming.utils.*; import com.alibaba.nacos.common.util.HttpMethod; import com.alibaba.nacos.common.util.UuidUtils; import java.io.IOException; import java.io.StringReader; import java.net.HttpURLConnection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; +import java.util.*; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; @@ -268,7 +258,7 @@ public class NamingProxy { case none: break; case label: - ExpressionSelector expressionSelector = (ExpressionSelector)selector; + ExpressionSelector expressionSelector = (ExpressionSelector) selector; params.put("selector", JSON.toJSONString(expressionSelector)); break; default: @@ -344,10 +334,6 @@ public class NamingProxy { return StringUtils.EMPTY; } - NAMING_LOGGER.error("[CALL-SERVER] failed to req API:" + HttpClient.getPrefix() + curServer - + api + ". code:" - + result.code + " msg: " + result.content); - throw new NacosException(NacosException.SERVER_ERROR, "failed to req API:" + HttpClient.getPrefix() + curServer + api + ". code:" + result.code + " msg: " + result.content); @@ -374,8 +360,10 @@ public class NamingProxy { String server = servers.get(index); try { return callServer(api, params, server, method); + } catch (NacosException e) { + NAMING_LOGGER.error("request {} failed.", server, e); } catch (Exception e) { - NAMING_LOGGER.error("[NA] req api:" + api + " failed, server(" + server, e); + NAMING_LOGGER.error("request {} failed.", server, e); } index = (index + 1) % servers.size();