cgivre commented on code in PR #3031:
URL: https://github.com/apache/drill/pull/3031#discussion_r2535173544
##########
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/auth/DrillErrorHandler.java:
##########
@@ -18,25 +18,49 @@
package org.apache.drill.exec.server.rest.auth;
import org.apache.drill.exec.server.rest.WebServerConstants;
-import org.eclipse.jetty.server.handler.ErrorHandler;
+import org.eclipse.jetty.ee10.servlet.ErrorPageErrorHandler;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.util.Callback;
-import javax.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.Writer;
/**
- * Custom ErrorHandler class for Drill's WebServer to have better error
message in case when SPNEGO login failed and
- * what to do next. In all other cases this would use the generic error page.
+ * Custom ErrorHandler class for Drill's WebServer to handle errors
appropriately based on the request type.
+ * - For JSON API endpoints (*.json), returns JSON error responses
+ * - For SPNEGO login failures, provides helpful HTML error page
+ * - For all other cases, returns standard HTML error page
*/
-public class DrillErrorHandler extends ErrorHandler {
+public class DrillErrorHandler extends ErrorPageErrorHandler {
+
+ @Override
+ public boolean handle(Request target, org.eclipse.jetty.server.Response
response, Callback callback) throws Exception {
+ // Check if this is a JSON API request
+ String pathInContext = Request.getPathInContext(target);
+ if (pathInContext != null && pathInContext.endsWith(".json")) {
+ // For JSON API endpoints, return JSON error response instead of HTML
+ response.getHeaders().put("Content-Type", "application/json");
Review Comment:
Fixed.
--
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]