diff --git a/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java b/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java index 91429201fe..6644ef1e00 100644 --- a/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java +++ b/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java @@ -290,6 +290,23 @@ public class MockApiUtils { } } } + if(respObj.containsKey("statusCode")){ + JSONArray statusCodeArray = respObj.getJSONArray("statusCode"); + if(statusCodeArray != null){ + for(int i = 0; i < statusCodeArray.size(); i ++){ + JSONObject object = statusCodeArray.getJSONObject(i); + if(object.containsKey("name")){ + try{ + int code = Integer.parseInt(object.getString("name")); + returnMap.put("code",code+""); + break; + }catch (Exception e){ + LogUtil.error(e); + } + } + } + } + } } catch (Exception e) { MSException.throwException(e); } diff --git a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java index 3d2ea27d3f..a5d4e61353 100644 --- a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java +++ b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java @@ -1131,6 +1131,21 @@ public class MockConfigService { returnStr = this.updateHttpServletResponse(finalExpectConfig, url, requestHeaderMap, mockParams, response); break; } + if(!isMatch){ + Map apiResponseMap = MockApiUtils.getApiResponse(api.getResponse()); + if(MapUtils.isNotEmpty(apiResponseMap)){ + returnStr = apiResponseMap.get("returnMsg"); + if(StringUtils.isNotEmpty(returnStr)){ + isMatch = true; + int code = 200; + if(apiResponseMap.containsKey("code")){ + code = Integer.parseInt(apiResponseMap.get("code")); + } + response.setStatus(code); + break; + } + } + } } } @@ -1173,6 +1188,21 @@ public class MockConfigService { break; } } + if(!isMatch){ + Map apiResponseMap = MockApiUtils.getApiResponse(api.getResponse()); + if(MapUtils.isNotEmpty(apiResponseMap)){ + returnStr = apiResponseMap.get("returnMsg"); + if(StringUtils.isNotEmpty(returnStr)){ + isMatch = true; + int code = 200; + if(apiResponseMap.containsKey("code")){ + code = Integer.parseInt(apiResponseMap.get("code")); + } + response.setStatus(code); + break; + } + } + } } }