Jelajahi Sumber

Merge branch 'master' of http://git.qmth.com.cn/ExamCloud-3/examcloud-web.git

WANG 5 tahun lalu
induk
melakukan
45b64073f1

+ 14 - 6
src/main/java/cn/com/qmth/examcloud/web/support/CustomExceptionHandler.java

@@ -64,6 +64,8 @@ public class CustomExceptionHandler {
 		if (null == cause) {
 			body = new StatusResponse(AppSelfHolder.get().getAppCode() + "-500", "系统异常");
 			cause = e;
+		} else if (cause instanceof ApiFlowLimitedException) {
+			body = new StatusResponse("503", "limited");
 		} else if (cause instanceof StatusException) {
 			StatusException se = (StatusException) cause;
 			body = new StatusResponse(AppSelfHolder.get().getAppCode() + "-" + se.getCode(),
@@ -98,8 +100,10 @@ public class CustomExceptionHandler {
 		} else if (cause instanceof SequenceLockException) {
 			body = new StatusResponse(AppSelfHolder.get().getAppCode() + "-500",
 					cause.getMessage());
-		} else if (cause instanceof org.springframework.jdbc.CannotGetJdbcConnectionException) {
-			body = new StatusResponse(AppSelfHolder.get().getAppCode() + "-500", "网络拥堵,请稍后重试");
+		} else if (cause instanceof org.springframework.jdbc.CannotGetJdbcConnectionException
+				|| cause instanceof org.springframework.orm.jpa.JpaSystemException
+				|| cause instanceof org.springframework.transaction.CannotCreateTransactionException) {
+			body = new StatusResponse("503", "limited");
 		} else {
 			body = new StatusResponse(AppSelfHolder.get().getAppCode() + "-500", "系统异常");
 			cause = e;
@@ -215,16 +219,20 @@ public class CustomExceptionHandler {
 
 		HttpStatus httpStatus = null;
 		if (alwaysOK) {
-			if (t instanceof ApiFlowLimitedException) {
+			if (t instanceof ApiFlowLimitedException
+					|| t instanceof org.springframework.jdbc.CannotGetJdbcConnectionException
+					|| t instanceof org.springframework.orm.jpa.JpaSystemException
+					|| t instanceof org.springframework.transaction.CannotCreateTransactionException) {
 				httpStatus = HttpStatus.SERVICE_UNAVAILABLE;
-				printStackTrace = false;
 			} else {
 				httpStatus = HttpStatus.OK;
 			}
 		} else {
-			if (t instanceof ApiFlowLimitedException) {
+			if (t instanceof ApiFlowLimitedException
+					|| t instanceof org.springframework.jdbc.CannotGetJdbcConnectionException
+					|| t instanceof org.springframework.orm.jpa.JpaSystemException
+					|| t instanceof org.springframework.transaction.CannotCreateTransactionException) {
 				httpStatus = HttpStatus.SERVICE_UNAVAILABLE;
-				printStackTrace = false;
 			} else {
 				httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
 			}