GlobalExceptionHandler.java
1.06 KB
package com.glsx.exception;
import cn.com.glsx.openplatform.enums.ResultCodeEnum;
import cn.com.glsx.openplatform.exception.BusinessException;
import cn.com.glsx.openplatform.vo.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* <p>Description:
* <p>Project: open-platform-admin
*
* @author wbh
* @date 2020-12-16
*/
@RestControllerAdvice
public class GlobalExceptionHandler {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@ExceptionHandler({BusinessException.class})
public R handleBusinessException(BusinessException e) {
this.logger.error("!!!! ERROR", e);
return R.error(e.getCode(), e.getMessage());
}
@ExceptionHandler({Throwable.class})
public R handlerOtherException(Throwable e) {
this.logger.error("!!!! ERROR", e);
return R.error(ResultCodeEnum.SERVER_ERROR.getCode(),
ResultCodeEnum.SERVER_ERROR.getMsg());
}
}