package cc.smtweb.framework.core.exception;

import cc.smtweb.framework.core.common.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Akmm at 2022-09-07 20:13
 * 异常统一处理
 */
@ControllerAdvice
public class SwExceptionHandler {
    /**
     * 系统异常处理
     *
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e) {
        if (e instanceof BizException) {
            return R.error(((BizException) e).getCode(), e.getMessage());
        }
        e.printStackTrace();
        return R.error("系统异常，请联系技术支持人员！");
    }
}
