ChejiaSmartExceptionHandler.java 1.44 KB
package cn.com.glsx.smart.common.exception;

import com.glsx.plat.core.web.R;
import com.glsx.plat.exception.GlobalExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <p>Description:
 * <p>Project: chejia-smart
 *
 * @author wbh
 * @date 2021-03-16
 */
@Slf4j
@RestControllerAdvice
public class ChejiaSmartExceptionHandler extends GlobalExceptionHandler {
    @ExceptionHandler({ChejiaBusinessException.class})
    public R handleBusinessException(ChejiaBusinessException e) {
        log.error("业务异常", e);
        R r = e.getResultEntity();
        return R.error(r.getCode(), r.getMessage());
    }

    @ExceptionHandler({CarKeyException.class})
    public R handleCarKeyException(CarKeyException e) {
        log.error("车钥匙异常", e);
        return R.error(e.getCode(), e.getMessage());
    }

    //@ExceptionHandler({ServletRequestBindingException.class, MethodArgumentNotValidException.class,
    //        BindException.class})
    //public R handleBindException(Exception e) {
    //    log.error("参数错误", e);
    //    return R.error(ResultEnum.PARAM_ERROR.getCode(), ResultEnum.PARAM_ERROR.getMessage());
    //}
    //
    //@ExceptionHandler(Exception.class)
    //public R handleException(Exception e) {
    //    log.error("未知异常", e);
    //    return R.error(e.getMessage());
    //}
}