From f3637227614f3f7efa372d827f4dafb7cc8a85bf Mon Sep 17 00:00:00 2001
From: 李林 <z1292839451@163.com>
Date: 星期四, 28 十二月 2023 11:24:12 +0800
Subject: [PATCH] 第二阶段

---
 framework/src/main/java/com/yuanchu/mom/handler/GlobalExceptionHandler.java |   51 +++++++++++++++++++++++++++++----------------------
 1 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/framework/src/main/java/com/yuanchu/mom/handler/GlobalExceptionHandler.java b/framework/src/main/java/com/yuanchu/mom/handler/GlobalExceptionHandler.java
index cc99c2d..7d8679b 100644
--- a/framework/src/main/java/com/yuanchu/mom/handler/GlobalExceptionHandler.java
+++ b/framework/src/main/java/com/yuanchu/mom/handler/GlobalExceptionHandler.java
@@ -1,5 +1,6 @@
 package com.yuanchu.mom.handler;
 
+import com.yuanchu.mom.exception.ErrorException;
 import com.yuanchu.mom.exception.MyFileException;
 import com.yuanchu.mom.vo.Result;
 import lombok.extern.slf4j.Slf4j;
@@ -38,7 +39,7 @@
     @ExceptionHandler(SQLException.class)
     public Result<?> handlerSQLException(SQLException e) {
         log.error(e.getMessage().toLowerCase(), e);
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏁版嵁鎿嶄綔澶辫触锛佽鑱旂郴绠$悊鍛�");
     }
 
@@ -54,14 +55,14 @@
         log.error(String.valueOf(e));
         String message = e.getCause().getMessage();
         String[] split = message.split("'");
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("閲嶅娣诲姞锛氥��" + split[1] + "銆戞搷浣滃け璐ワ紒");
     }
 
     @ExceptionHandler
     public Result<?> NullPointerException(NullPointerException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("閮ㄥ垎鍙傛暟涓虹┖锛岃妫�鏌ワ紒");
     }
 
@@ -71,7 +72,7 @@
     @ExceptionHandler(RuntimeException.class)
     public Result<?> runtimeExceptionHandler(RuntimeException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("杩愯鏃跺紓甯�");
     }
 
@@ -81,7 +82,7 @@
     @ExceptionHandler(ClassCastException.class)
     public Result<?> classCastExceptionHandler(ClassCastException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("绫诲瀷杞崲寮傚父");
     }
 
@@ -91,7 +92,7 @@
     @ExceptionHandler(FileNotFoundException.class)
     public Result<?> FileNotFoundException(FileNotFoundException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏂囦欢鏈壘鍒板紓甯�");
     }
 
@@ -101,7 +102,7 @@
     @ExceptionHandler(NumberFormatException.class)
     public Result<?> NumberFormatException(NumberFormatException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏁板瓧鏍煎紡寮傚父");
     }
 
@@ -111,7 +112,7 @@
     @ExceptionHandler(SecurityException.class)
     public Result<?> SecurityException(SecurityException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("瀹夊叏寮傚父");
     }
 
@@ -121,7 +122,7 @@
     @ExceptionHandler(TypeNotPresentException.class)
     public Result<?> TypeNotPresentException(TypeNotPresentException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("绫诲瀷涓嶅瓨鍦ㄥ紓甯�");
     }
 
@@ -131,7 +132,7 @@
     @ExceptionHandler(IOException.class)
     public Result<?> iOExceptionHandler(IOException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("IO寮傚父");
     }
 
@@ -141,7 +142,7 @@
     @ExceptionHandler(NoSuchMethodException.class)
     public Result<?> noSuchMethodExceptionHandler(NoSuchMethodException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏈煡鏂规硶寮傚父");
     }
 
@@ -151,7 +152,7 @@
     @ExceptionHandler(IndexOutOfBoundsException.class)
     public Result<?> indexOutOfBoundsExceptionHandler(IndexOutOfBoundsException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏁扮粍瓒婄晫寮傚父");
     }
 
@@ -161,7 +162,7 @@
     @ExceptionHandler(BadSqlGrammarException.class)
     public Result<?> BadSqlGrammarException(BadSqlGrammarException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("sql璇硶閿欒寮傚父");
     }
 
@@ -171,7 +172,7 @@
     @ExceptionHandler(NoSuchBeanDefinitionException.class)
     public Result<?> NoSuchBeanDefinitionException(NoSuchBeanDefinitionException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏃犳硶娉ㄥ叆bean");
     }
 
@@ -181,7 +182,7 @@
     @ExceptionHandler({HttpMessageNotReadableException.class})
     public Result<?> requestNotReadable(HttpMessageNotReadableException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("Http娑堟伅涓嶅彲璇�");
     }
 
@@ -191,17 +192,17 @@
     @ExceptionHandler({TypeMismatchException.class})
     public Result<?> requestTypeMismatch(TypeMismatchException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏈嶅姟鍣ㄥ紓甯�");
     }
 
     /**
-     * 500閿欒
+     * 201閿欒
      */
     @ExceptionHandler({ConversionNotSupportedException.class, HttpMessageNotWritableException.class})
-    public Result<?> server500(RuntimeException e) {
+    public Result<?> server201(RuntimeException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏈嶅姟鍣ㄥ紓甯�");
     }
 
@@ -211,7 +212,7 @@
     @ExceptionHandler({StackOverflowError.class})
     public Result<?> requestStackOverflow(StackOverflowError e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("鏍堟孩鍑哄紓甯�");
     }
 
@@ -221,7 +222,7 @@
     @ExceptionHandler({ArithmeticException.class})
     public Result<?> arithmeticException(ArithmeticException e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("闄ゆ暟涓嶈兘涓�0寮傚父");
     }
 
@@ -264,6 +265,12 @@
         return Result.fail("鎶辨瓑涓嶆敮鎸併��" + e.getMessage() +"銆戝悗缂�鐨勬枃浠讹紒");
     }
 
+    @ExceptionHandler({ErrorException.class})
+    public Result<?> errorException(Exception e) {
+        log.error(e.getMessage());
+        return Result.fail(e.getMessage());
+    }
+
     /** 鍏朵粬閿欒 */
     /**
      * 鍏朵粬閿欒
@@ -271,7 +278,7 @@
     @ExceptionHandler({Exception.class})
     public Result<?> exception(Exception e) {
         e.printStackTrace();
-        response.setStatus(500);
+        response.setStatus(201);
         return Result.fail("缃戠粶杩炴帴澶辫触锛岃閫�鍑哄悗鍐嶈瘯");
     }
 }

--
Gitblit v1.9.3