GlobalExceptionHandler.java
1.09 KB
package com.viontech.fanxing.commons.base;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.keliu.util.JsonMessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* .
*
* @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) {
log.error("", e);
return JsonMessageUtil.getErrorJsonMsg(e.getMessage());
}
@ExceptionHandler(FanXingException.class)
public Object fanXingExceptionHandler(FanXingException fanXingException) {
JsonMessageUtil.JsonMessage errorJsonMsg = JsonMessageUtil.getErrorJsonMsg(fanXingException.getMessage());
errorJsonMsg.setData(fanXingException.getData());
log.error("", fanXingException);
return errorJsonMsg;
}
}