From 4497f5b1e322eba5ec519ebc1955317ed656aa8e Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 26 十二月 2024 14:31:15 +0800
Subject: [PATCH] Merge branch 'master' into cnas
---
framework/src/main/java/com/yuanchu/mom/handler/GlobalExceptionHandler.java | 54 +++++++++++++++++++++++++++++++-----------------------
1 files changed, 31 insertions(+), 23 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..3c7a631 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,8 +182,8 @@
@ExceptionHandler({HttpMessageNotReadableException.class})
public Result<?> requestNotReadable(HttpMessageNotReadableException e) {
e.printStackTrace();
- response.setStatus(500);
- return Result.fail("Http娑堟伅涓嶅彲璇�");
+ response.setStatus(201);
+ return Result.fail("鍙傛暟浼犻�掗敊璇�");
}
/**
@@ -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寮傚父");
}
@@ -255,6 +256,7 @@
}else {
msg="鏂囦欢涓婁紶澶辫触銆愭湇鍔″櫒寮傚父銆�";
}
+ e.printStackTrace();
return Result.fail(msg);
}
@@ -264,6 +266,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 +279,7 @@
@ExceptionHandler({Exception.class})
public Result<?> exception(Exception e) {
e.printStackTrace();
- response.setStatus(500);
+ response.setStatus(201);
return Result.fail("缃戠粶杩炴帴澶辫触锛岃閫�鍑哄悗鍐嶈瘯");
}
}
--
Gitblit v1.9.3