
artoria.exception.spring.ServletErrorHandlerExceptionHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artoria-extend Show documentation
Show all versions of artoria-extend Show documentation
Artoria is a java technology framework based on the facade pattern.
The newest version!
package artoria.exception.spring;
import artoria.exception.ServletErrorHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Simple exception handler.
* @author Kahle
*/
@ControllerAdvice
public class ServletErrorHandlerExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(ServletErrorHandlerExceptionHandler.class);
private final ServletErrorHandler servletErrorHandler;
@Autowired
public ServletErrorHandlerExceptionHandler(ServletErrorHandler servletErrorHandler) {
this.servletErrorHandler = servletErrorHandler;
log.info("The exception handler based on servlet error handler was initialized success. ");
}
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler(Exception.class)
public Object handleException(HttpServletRequest request, HttpServletResponse response, Exception ex) {
log.error("Caught an unhandled exception. ", ex);
return servletErrorHandler.handle(request, response, ex);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy