TSK-1152: removed stacktrace from log for InvalidArgumentException.

This commit is contained in:
Holger Hagen 2020-03-05 10:18:25 +01:00
parent ad31328e1b
commit 545c706547
1 changed files with 11 additions and 7 deletions

View File

@ -44,7 +44,7 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
@ExceptionHandler(InvalidArgumentException.class) @ExceptionHandler(InvalidArgumentException.class)
protected ResponseEntity<Object> handleInvalidArgument( protected ResponseEntity<Object> handleInvalidArgument(
InvalidArgumentException ex, WebRequest req) { InvalidArgumentException ex, WebRequest req) {
return buildResponse(ex, req, HttpStatus.BAD_REQUEST); return buildResponse(ex, req, HttpStatus.BAD_REQUEST, false);
} }
@ExceptionHandler(NotAuthorizedException.class) @ExceptionHandler(NotAuthorizedException.class)
@ -150,13 +150,17 @@ public class TaskanaRestExceptionHandler extends ResponseEntityExceptionHandler
} }
private ResponseEntity<Object> buildResponse(Exception ex, WebRequest req, HttpStatus status) { private ResponseEntity<Object> buildResponse(Exception ex, WebRequest req, HttpStatus status) {
TaskanaErrorData errorData = new TaskanaErrorData(status, ex, req); return buildResponse(ex, req, status, true);
logError(ex, errorData);
return ResponseEntity.status(status).body(errorData);
} }
private void logError(Exception ex, TaskanaErrorData errorData) { private ResponseEntity<Object> buildResponse(
LOGGER.error( Exception ex, WebRequest req, HttpStatus status, boolean logExceptionOnError) {
"Error occurred during processing of rest request:\n {}" + errorData.toString(), ex); TaskanaErrorData errorData = new TaskanaErrorData(status, ex, req);
if (logExceptionOnError) {
LOGGER.error("Error occurred during processing of rest request: " + errorData.toString(), ex);
} else {
LOGGER.debug("Error occurred during processing of rest request: " + errorData.toString(), ex);
}
return ResponseEntity.status(status).body(errorData);
} }
} }