62 lines
2.2 KiB
Java
62 lines
2.2 KiB
Java
package eu.dnetlib.repo.manager.controllers;
|
|
|
|
|
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
|
import eu.dnetlib.repo.manager.exception.EndPointException;
|
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
|
import eu.dnetlib.repo.manager.exception.ServerError;
|
|
import eu.dnetlib.repo.manager.shared.BrokerException;
|
|
import org.apache.log4j.LogManager;
|
|
import org.apache.log4j.Logger;
|
|
import org.json.JSONException;
|
|
import org.springframework.core.Ordered;
|
|
import org.springframework.core.annotation.Order;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.security.access.AccessDeniedException;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.net.UnknownHostException;
|
|
|
|
|
|
@ControllerAdvice
|
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
|
public class GenericControllerAdvice {
|
|
|
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
|
@ExceptionHandler(ResourceNotFoundException.class)
|
|
@ResponseBody
|
|
public ServerError securityException(HttpServletRequest req, Exception ex) {
|
|
return new ServerError(req.getRequestURL().toString(),ex);
|
|
}
|
|
|
|
@ResponseStatus(HttpStatus.FORBIDDEN)
|
|
@ExceptionHandler(AccessDeniedException.class)
|
|
@ResponseBody
|
|
public ServerError accessDeniedException(HttpServletRequest req, Exception ex) {
|
|
return new ServerError(req.getRequestURL().toString(),ex);
|
|
}
|
|
|
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
|
@ExceptionHandler(UnknownHostException.class)
|
|
@ResponseBody
|
|
public ServerError unknownHostException(HttpServletRequest req, Exception ex) {
|
|
return new ServerError(req.getRequestURL().toString(),ex);
|
|
}
|
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
@ExceptionHandler({JSONException.class,BrokerException.class,ValidatorServiceException.class})
|
|
@ResponseBody
|
|
public ServerError internalException(HttpServletRequest req, Exception ex) {
|
|
return new ServerError(req.getRequestURL().toString(),ex);
|
|
}
|
|
|
|
@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
|
|
@ExceptionHandler(EndPointException.class)
|
|
@ResponseBody
|
|
public ServerError endPointException(HttpServletRequest req, Exception ex) {
|
|
return new ServerError(req.getRequestURL().toString(),ex);
|
|
}
|
|
|
|
}
|