adarshsanjeev commented on code in PR #18487:
URL: https://github.com/apache/druid/pull/18487#discussion_r2335774063


##########
processing/src/main/java/org/apache/druid/common/exception/PersonaBasedErrorTransformStrategy.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.common.exception;
+
+import org.apache.druid.error.DruidException;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.emitter.EmittingLogger;
+import org.apache.druid.java.util.emitter.service.AlertEvent;
+
+import java.util.UUID;
+import java.util.function.Function;
+
+public class PersonaBasedErrorTransformStrategy implements 
ErrorResponseTransformStrategy
+{
+  private static final String ERROR_WITH_ID_TEMPLATE = "Could not process the 
query, please contact your administrator "
+                                                       + "with Error ID [%s] 
if the issue persists.";
+  private static final EmittingLogger LOG = new 
EmittingLogger(PersonaBasedErrorTransformStrategy.class);
+
+  public static final PersonaBasedErrorTransformStrategy INSTANCE = new 
PersonaBasedErrorTransformStrategy();
+
+  @Override
+  public Exception transformIfNeeded(SanitizableException exception)
+  {
+    if (exception instanceof DruidException) {
+      final DruidException druidException = (DruidException) exception;
+      if (druidException.getTargetPersona() == DruidException.Persona.USER) {
+        return druidException;
+      } else {
+        return exception.sanitize(s -> {
+          final String errorId = UUID.randomUUID().toString();
+          LOG.makeAlert(druidException, StringUtils.format("Error ID: [%s]", 
errorId))
+             .addData(druidException.getContext())
+             .severity(AlertEvent.Severity.ANOMALY)
+             .emit();
+          return StringUtils.format(ERROR_WITH_ID_TEMPLATE, errorId);
+        });

Review Comment:
   I've attempted to make changes according to what you suggested, please take 
a look. I did not understand why we would need a `Optional<String> errorId` 
instead of always passing one. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to