From 7ea5eece501c98a91555a5358931367e78e9d23b Mon Sep 17 00:00:00 2001
From: baizonghao <1719256278@qq.com>
Date: 星期四, 25 五月 2023 15:40:09 +0800
Subject: [PATCH] 11

---
 src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java |   29 ++++++++++-------------------
 1 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java b/src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java
index c153ac9..9e267cc 100644
--- a/src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java
+++ b/src/main/java/com/example/jz/config/DefaultExceptionHandlerConfig.java
@@ -1,9 +1,8 @@
 package com.example.jz.config;
 
-import com.example.jz.enums.BusinessHttpStatus;
 import com.example.jz.exception.BusinessException;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
+import com.example.jz.modle.R;
+import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Controller;
 import org.springframework.validation.BindException;
 import org.springframework.web.bind.MethodArgumentNotValidException;
@@ -17,23 +16,15 @@
 @RestControllerAdvice
 public class DefaultExceptionHandlerConfig {
 
-
-    @ExceptionHandler(BindException.class)
-    public ResponseEntity<String> bindExceptionHandler(BindException e) {
-        e.printStackTrace();
-        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
-
-    }
-
-    @ExceptionHandler(MethodArgumentNotValidException.class)
-    public ResponseEntity<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
-        e.printStackTrace();
-        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
-    }
-
     @ExceptionHandler(BusinessException.class)
-    public ResponseEntity<String> unauthorizedExceptionHandler(BusinessException e) {
+    public R<String> unauthorizedExceptionHandler(BusinessException e) {
         e.printStackTrace();
-        return ResponseEntity.status(e.getHttpStatusCode()).body(e.getMessage());
+        return R.failed(e.getMessage());
+    }
+
+    @ExceptionHandler(Exception.class)
+    public R<String> ExceptionHandler(Exception e) {
+        e.printStackTrace();
+        return R.failed(e.getMessage());
     }
 }

--
Gitblit v1.8.0