package eu.eudat.controllers.controllerhandler; import eu.eudat.core.logger.Logger; import eu.eudat.exceptions.security.UnauthorisedException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; 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 javax.annotation.Priority; /** * Created by ikalyvas on 6/12/2018. */ @ControllerAdvice @Priority(4) public class ControllerUnauthorisedHandler { private Logger logger; @Autowired public ControllerUnauthorisedHandler(Logger logger) { this.logger = logger; } @ExceptionHandler(UnauthorisedException.class) @ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseBody public void processValidationError(UnauthorisedException ex) { this.logger.error(ex, ex.getMessage()); return; } }