Ray Milkey
Committed by Gerrit Code Review

ONOS-3369: log an exception on REST server errors

Change-Id: I407ed7576ff79b5781d2a688c78367266643aaea
...@@ -29,6 +29,11 @@ import static com.google.common.base.Strings.isNullOrEmpty; ...@@ -29,6 +29,11 @@ import static com.google.common.base.Strings.isNullOrEmpty;
29 public abstract class AbstractMapper<E extends Throwable> implements ExceptionMapper<E> { 29 public abstract class AbstractMapper<E extends Throwable> implements ExceptionMapper<E> {
30 30
31 /** 31 /**
32 + * Holds the current exception for use in subclasses.
33 + */
34 + protected Throwable error;
35 +
36 + /**
32 * Returns the response status to be given when the exception occurs. 37 * Returns the response status to be given when the exception occurs.
33 * 38 *
34 * @return response status 39 * @return response status
...@@ -37,6 +42,7 @@ public abstract class AbstractMapper<E extends Throwable> implements ExceptionMa ...@@ -37,6 +42,7 @@ public abstract class AbstractMapper<E extends Throwable> implements ExceptionMa
37 42
38 @Override 43 @Override
39 public Response toResponse(E exception) { 44 public Response toResponse(E exception) {
45 + error = exception;
40 return response(responseStatus(), exception).build(); 46 return response(responseStatus(), exception).build();
41 } 47 }
42 48
...@@ -50,6 +56,7 @@ public abstract class AbstractMapper<E extends Throwable> implements ExceptionMa ...@@ -50,6 +56,7 @@ public abstract class AbstractMapper<E extends Throwable> implements ExceptionMa
50 */ 56 */
51 protected Response.ResponseBuilder response(Response.Status status, 57 protected Response.ResponseBuilder response(Response.Status status,
52 Throwable exception) { 58 Throwable exception) {
59 + error = exception;
53 ObjectMapper mapper = new ObjectMapper(); 60 ObjectMapper mapper = new ObjectMapper();
54 String message = messageFrom(exception); 61 String message = messageFrom(exception);
55 ObjectNode result = mapper.createObjectNode() 62 ObjectNode result = mapper.createObjectNode()
......
...@@ -18,13 +18,19 @@ package org.onosproject.rest.exceptions; ...@@ -18,13 +18,19 @@ package org.onosproject.rest.exceptions;
18 import javax.ws.rs.core.Response; 18 import javax.ws.rs.core.Response;
19 import javax.ws.rs.ext.Provider; 19 import javax.ws.rs.ext.Provider;
20 20
21 +import org.slf4j.Logger;
22 +
23 +import static org.slf4j.LoggerFactory.getLogger;
24 +
21 /** 25 /**
22 * Mapper for service not found exceptions to the INTERNAL_SERVER_ERROR response code. 26 * Mapper for service not found exceptions to the INTERNAL_SERVER_ERROR response code.
23 */ 27 */
24 @Provider 28 @Provider
25 public class ServerErrorMapper extends AbstractMapper<RuntimeException> { 29 public class ServerErrorMapper extends AbstractMapper<RuntimeException> {
30 + private static final Logger log = getLogger(ServerErrorMapper.class);
26 @Override 31 @Override
27 protected Response.Status responseStatus() { 32 protected Response.Status responseStatus() {
33 + log.warn("Unhandled REST exception", error);
28 return Response.Status.INTERNAL_SERVER_ERROR; 34 return Response.Status.INTERNAL_SERVER_ERROR;
29 } 35 }
30 } 36 }
......