From dd73bbc7132f7b126b8fc2faabf2827b49622d21 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 23 Oct 2023 09:28:40 +0800
Subject: [PATCH] 获取计划最近一条
---
src/main/java/com/dji/sample/component/GlobalExceptionHandler.java | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
index b0a9fbf..c590caf 100644
--- a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
+++ b/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.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -29,12 +30,13 @@
@ExceptionHandler(NullPointerException.class)
public ResponseResult nullPointerExceptionHandler(NullPointerException e) {
e.printStackTrace();
- return ResponseResult.error("A null object appeared.");
+ return ResponseResult.error("出现空对象");
}
- @ExceptionHandler(MethodArgumentNotValidException.class)
- public ResponseResult methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
- return ResponseResult.error(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
+ @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
+ public ResponseResult methodArgumentNotValidExceptionHandler(BindException e) {
+ e.printStackTrace();
+ return ResponseResult.error(e.getFieldError().getField() + e.getFieldError().getDefaultMessage());
}
}
--
Gitblit v1.9.3