From 8077e8b67bc017a9e0016180a6eacc114cec28c8 Mon Sep 17 00:00:00 2001
From: DJIsean <102007705+DJIsean@users.noreply.github.com>
Date: Thu, 15 Dec 2022 16:14:24 +0800
Subject: [PATCH] Update DeviceServiceImpl.java

---
 src/main/java/com/dji/sample/component/GlobalExceptionHandler.java |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
index 1d5eb14..953fd2d 100644
--- a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
+++ b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
@@ -1,6 +1,8 @@
 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;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -30,4 +32,11 @@
         e.printStackTrace();
         return ResponseResult.error("A null object appeared.");
     }
+
+    @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
+    public ResponseResult methodArgumentNotValidExceptionHandler(BindException e) {
+        e.printStackTrace();
+        return ResponseResult.error(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
+    }
+
 }

--
Gitblit v1.9.3