From 4412631db62a5322317cc74233bdbc213d48f11a Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 27 Sep 2022 17:37:18 -0700 Subject: [PATCH] Address PR feedback. Signed-off-by: Yury-Fridlyand --- .../java/org/opensearch/sql/common/utils/QueryContext.java | 7 +++++++ .../org/opensearch/sql/legacy/plugin/RestSqlAction.java | 3 ++- .../opensearch/sql/legacy/plugin/RestSqlStatsAction.java | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/opensearch/sql/common/utils/QueryContext.java b/common/src/main/java/org/opensearch/sql/common/utils/QueryContext.java index d3c4299876..553d5bea39 100644 --- a/common/src/main/java/org/opensearch/sql/common/utils/QueryContext.java +++ b/common/src/main/java/org/opensearch/sql/common/utils/QueryContext.java @@ -69,6 +69,13 @@ public static String getError() { return ThreadContext.get(ERROR_KEY); } + /** + * Clear saved error messages. + */ + public static void clearError() { + ThreadContext.remove(ERROR_KEY); + } + /** * Wraps a given instance of {@link Runnable} into a new one which gets all the diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java index 3090a94564..c8d352e5a5 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlAction.java @@ -137,6 +137,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli Metrics.getInstance().getNumericalMetric(MetricName.REQ_TOTAL).increment(); Metrics.getInstance().getNumericalMetric(MetricName.REQ_COUNT_TOTAL).increment(); + QueryContext.clearError(); QueryContext.addRequestId(); try { @@ -276,7 +277,7 @@ private static boolean isExplainRequest(final RestRequest request) { return request.path().endsWith("/_explain"); } - public static boolean isClientError(Exception e) { + private static boolean isClientError(Exception e) { return e instanceof NullPointerException // NPE is hard to differentiate but more likely caused by bad query || e instanceof SqlParseException || e instanceof ParserException diff --git a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlStatsAction.java b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlStatsAction.java index 5b48ef6710..417ae4869b 100644 --- a/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlStatsAction.java +++ b/legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSqlStatsAction.java @@ -67,6 +67,7 @@ public List replacedRoutes() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { + QueryContext.clearError(); QueryContext.addRequestId(); try {