package ch.uzh.csg.reimbursement.rest;

import static org.springframework.http.HttpStatus.BAD_REQUEST;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import ch.uzh.csg.reimbursement.dto.ErrorDto;
import ch.uzh.csg.reimbursement.model.exception.BusinessException;
import ch.uzh.csg.reimbursement.model.exception.ServiceException;

@ControllerAdvice
class GlobalControllerExceptionHandler {
	@ResponseStatus(BAD_REQUEST)
	@ExceptionHandler(RuntimeException.class)
	@ResponseBody ErrorDto handleRuntimeException(HttpServletRequest req, RuntimeException ex) {
		if(!(ex instanceof BusinessException)){
			ex = new ServiceException();
		}
		return new ErrorDto(req.getRequestURL(), ex);
	}
}

@@ -140,24 +140,81 @@
 etRequest;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import org.s
@@ -266,16 +266,16 @@
 Advice;%0A
-
 import o
@@ -654,16 +654,23 @@
 rAdvice%0A
+public 
 class Gl
@@ -702,16 +702,110 @@
 ndler %7B%0A
+%09%0A%09private Logger logger = LoggerFactory.getLogger(GlobalControllerExceptionHandler.class);%0A%09%0A
 %09@Respon
@@ -1003,17 +1003,56 @@
 eption))
-%7B
+ %7B%0A%09%09%09logger.error(ex.getMessage(), ex);
 %0A%09%09%09ex =

improve exception logging