GlobalExceptionHandler.java 1.25 KB
package com.glsx.smart.exception;

import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * <p>Description:
 * <p>Project: chejia-smart
 *
 * @author wbh
 * @date 2021-03-16
 * @deprecated 抛出异常,让上游服务捕获信息
 */
@Slf4j
//@RestControllerAdvice
@Deprecated
public class GlobalExceptionHandler {
    @ExceptionHandler({BusinessException.class})
    public R handleBusinessException(BusinessException e) {
        log.error("业务异常", e);
        return R.error(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());
    }
}