无人机项目后端代码
sean.zhou
2022-11-18 56df98ce4952239fbf7d0e99dbeb0e5c71531d6f
src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
@@ -1,6 +1,7 @@
package com.dji.sample.component;
import com.dji.sample.common.model.ResponseResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -30,4 +31,10 @@
        e.printStackTrace();
        return ResponseResult.error("A null object appeared.");
    }
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResponseResult methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
        return ResponseResult.error(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
    }
}