package org.synyx.urlaubsverwaltung.api;

import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
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 org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.synyx.urlaubsverwaltung.workingtime.NoValidWorkingTimeException;

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


/**
 * Handles exceptions and redirects to error page.
 */
@ControllerAdvice(annotations = RestController.class)
public class ApiExceptionHandlerControllerAdvice {

    @ResponseStatus(NO_CONTENT)
    @ExceptionHandler({NoValidWorkingTimeException.class})
    @ResponseBody
    public ErrorResponse handleException(IllegalStateException exception) {

        return new ErrorResponse(NO_CONTENT, exception);
    }

    @ResponseStatus(BAD_REQUEST)
    @ExceptionHandler({NumberFormatException.class, IllegalArgumentException.class})
    @ResponseBody
    public ErrorResponse handleException(IllegalArgumentException exception) {

        return new ErrorResponse(BAD_REQUEST, exception);
    }


    @ResponseStatus(BAD_REQUEST)
    @ExceptionHandler(MethodArgumentTypeMismatchException.class)
    @ResponseBody
    public ErrorResponse handleException(MethodArgumentTypeMismatchException exception) {

        return new ErrorResponse(BAD_REQUEST, exception);
    }


    @ResponseStatus(BAD_REQUEST)
    @ExceptionHandler(MissingServletRequestParameterException.class)
    @ResponseBody
    public ErrorResponse handleException(MissingServletRequestParameterException exception) {

        return new ErrorResponse(BAD_REQUEST, exception);
    }


    @ResponseStatus(HttpStatus.FORBIDDEN)
    @ExceptionHandler(AccessDeniedException.class)
    @ResponseBody
    public ErrorResponse handleException(AccessDeniedException exception) {

        return new ErrorResponse(HttpStatus.FORBIDDEN, exception);
    }


    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ErrorResponse handleException(Exception exception) {

        return new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
    }
}

@@ -226,73 +226,8 @@
 on;%0A
-import org.springframework.web.bind.annotation.ControllerAdvice;%0A
 impo
@@ -472,16 +472,22 @@
 ntroller
+Advice
 ;%0Aimport
@@ -830,16 +830,20 @@
 e.%0A */%0A@
+Rest
 Controll
@@ -854,44 +854,8 @@
 vice
-(annotations = RestController.class)
 %0Apub

Use @RestControllerAdvice