kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: MINOR: Log unexpected exceptions in Connect REST calls that generate 500s at a higher log level
Date Tue, 21 Nov 2017 04:29:42 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk e3c32391f -> f0276f5ca


MINOR: Log unexpected exceptions in Connect REST calls that generate 500s at a higher log
level

The ConnectExceptionMapper was originally intended to handle ConnectException errors for some
expected cases where we just want to always convert them to a certain response and the ExceptionMapper
was the easiest way to do that uniformly across the API. However, in the case that it's not
an expected subclass, we should log the information at the error level so the user can track
down the cause of the error.

This is only an initial improvement. We should probably also add a more general ExceptionMapper
to handle other exceptions we may not have caught and converted to ConnectException.

Author: Ewen Cheslack-Postava <me@ewencp.org>

Reviewers: Randall Hauch <rhauch@gmail.com>, Jason Gustafson <jason@confluent.io>

Closes #4227 from ewencp/better-connect-error-logging


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/f0276f5c
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/f0276f5c
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/f0276f5c

Branch: refs/heads/trunk
Commit: f0276f5ca2ebed2848055ccec875181f5db7ba51
Parents: e3c3239
Author: Ewen Cheslack-Postava <me@ewencp.org>
Authored: Mon Nov 20 20:29:33 2017 -0800
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Mon Nov 20 20:29:33 2017 -0800

----------------------------------------------------------------------
 .../rest/errors/ConnectExceptionMapper.java     | 28 +++++++++++++++-----
 1 file changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/f0276f5c/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/errors/ConnectExceptionMapper.java
----------------------------------------------------------------------
diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/errors/ConnectExceptionMapper.java
b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/errors/ConnectExceptionMapper.java
index d3be2e0..8678fbf 100644
--- a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/errors/ConnectExceptionMapper.java
+++ b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/errors/ConnectExceptionMapper.java
@@ -17,21 +17,26 @@
 package org.apache.kafka.connect.runtime.rest.errors;
 
 import org.apache.kafka.connect.errors.AlreadyExistsException;
-import org.apache.kafka.connect.errors.ConnectException;
 import org.apache.kafka.connect.errors.NotFoundException;
 import org.apache.kafka.connect.runtime.rest.entities.ErrorMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ExceptionMapper;
 
-public class ConnectExceptionMapper implements ExceptionMapper<ConnectException> {
+public class ConnectExceptionMapper implements ExceptionMapper<Exception> {
     private static final Logger log = LoggerFactory.getLogger(ConnectExceptionMapper.class);
 
+    @Context
+    private UriInfo uriInfo;
+
     @Override
-    public Response toResponse(ConnectException exception) {
-        log.debug("Uncaught exception in REST call: ", exception);
+    public Response toResponse(Exception exception) {
+        log.debug("Uncaught exception in REST call to /{}", uriInfo.getPath(), exception);
 
         if (exception instanceof ConnectRestException) {
             ConnectRestException restException = (ConnectRestException) exception;
@@ -52,8 +57,19 @@ public class ConnectExceptionMapper implements ExceptionMapper<ConnectException>
                     .build();
         }
 
-        return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                .entity(new ErrorMessage(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
exception.getMessage()))
+        if (!log.isDebugEnabled()) {
+            log.error("Uncaught exception in REST call to /{}", uriInfo.getPath(), exception);
+        }
+
+        final int statusCode;
+        if (exception instanceof WebApplicationException) {
+            Response.StatusType statusInfo = ((WebApplicationException) exception).getResponse().getStatusInfo();
+            statusCode = statusInfo.getStatusCode();
+        } else {
+            statusCode = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
+        }
+        return Response.status(statusCode)
+                .entity(new ErrorMessage(statusCode, exception.getMessage()))
                 .build();
     }
 }


Mime
View raw message