GlobalExceptionHandler.java 761 Bytes
package com.viontech.exception;

import com.viontech.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: zhuhai
 * Date: 2023-04-04
 * Time: 16:22
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ResultVo exception(Exception ex) {
        log.error("系统异常", ex);
        if (ex instanceof ServletRequestBindingException) {
            return ResultVo.error("400", "param is error");
        }
        return ResultVo.error();
    }
}