From 4b3d4dce8bfb3889bbb96d62f7b0cd23d6ffd8b9 Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Mon, 11 May 2015 10:47:25 -0400 Subject: [PATCH] DATAREST-539 - Log exception even if it has no message. --- .../webmvc/RepositoryRestExceptionHandler.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java index 6dd4c06ed..13c9f7693 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java @@ -33,6 +33,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -161,16 +162,17 @@ public class RepositoryRestExceptionHandler { private static ResponseEntity errorResponse(HttpStatus status, HttpHeaders headers, Exception exception) { - if (null != exception && null != exception.getMessage()) { + if (exception != null) { - LOG.error(exception.getMessage(), exception); + String message = exception.getMessage(); + LOG.error(message, exception); - return response(status, headers, new ExceptionMessage(exception)); - - } else { - - return response(status, headers, null); + if (StringUtils.hasText(message)) { + return response(status, headers, new ExceptionMessage(exception)); + } } + + return response(status, headers, null); } private static ResponseEntity response(HttpStatus status, HttpHeaders headers) {