GlobalExceptionHandler.java
841 Bytes
package com.viontech.storage.config;
import com.viontech.storage.entity.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
/**
* .
*
* @author 谢明辉
* @date 2020/6/4
*/
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(Exception.class)
public Object exceptionHandler(Exception e, HttpServletRequest request) {
log.error(request.getRequestURI() + "?" + Optional.ofNullable(request.getQueryString()).orElse(""), e);
return Message.error(e.getMessage());
}
}