Browse Source

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

WANG 5 years ago
parent
commit
fb0a8cdf1a

+ 15 - 16
src/main/java/cn/com/qmth/examcloud/web/support/CustomExceptionHandler.java

@@ -213,31 +213,30 @@ public class CustomExceptionHandler {
 			}
 		}
 
+		HttpStatus httpStatus = null;
 		if (alwaysOK) {
-			INTERFACE_LOG.error("[HTTP-RESP]. status=" + HttpStatus.OK.value());
-			if (printStackTrace) {
-				INTERFACE_LOG.error("[HTTP-RESP]. response=" + JsonUtil.toJson(body), t);
-			} else {
-				INTERFACE_LOG.error("[HTTP-RESP]. response=" + JsonUtil.toJson(body));
-			}
 			if (t instanceof ApiFlowLimitedException) {
-				return new ResponseEntity<StatusResponse>(body, HttpStatus.SERVICE_UNAVAILABLE);
+				httpStatus = HttpStatus.SERVICE_UNAVAILABLE;
 			} else {
-				return new ResponseEntity<StatusResponse>(body, HttpStatus.OK);
+				httpStatus = HttpStatus.OK;
 			}
 		} else {
-			INTERFACE_LOG.error("[HTTP-RESP]. status=" + HttpStatus.INTERNAL_SERVER_ERROR.value());
-			if (printStackTrace) {
-				INTERFACE_LOG.error("[HTTP-RESP]. response=" + JsonUtil.toJson(body), t);
-			} else {
-				INTERFACE_LOG.error("[HTTP-RESP]. response=" + JsonUtil.toJson(body));
-			}
 			if (t instanceof ApiFlowLimitedException) {
-				return new ResponseEntity<StatusResponse>(body, HttpStatus.SERVICE_UNAVAILABLE);
+				httpStatus = HttpStatus.SERVICE_UNAVAILABLE;
 			} else {
-				return new ResponseEntity<StatusResponse>(body, HttpStatus.INTERNAL_SERVER_ERROR);
+				httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
 			}
 		}
+
+		INTERFACE_LOG.error("[HTTP-RESP]. status=" + httpStatus.value());
+
+		if (printStackTrace) {
+			INTERFACE_LOG.error("[HTTP-RESP]. response=" + JsonUtil.toJson(body), t);
+		} else {
+			INTERFACE_LOG.error("[HTTP-RESP]. response=" + JsonUtil.toJson(body));
+		}
+
+		return new ResponseEntity<StatusResponse>(body, httpStatus);
 	}
 
 	/**