From fc9946eef7e16d816891afbadded19a2b1547e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=B0=8F=E5=90=8D=E7=9A=84=E6=9B=B2?= <951012707@qq.com> Date: Tue, 6 Feb 2024 17:18:52 +0800 Subject: [PATCH] fix: For the indexed set of ck and es, reset the status code to 200 when the result of es is a status of 404 --- .../ly/ckibana/handlers/ResolveIndexHandler.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ly/ckibana/handlers/ResolveIndexHandler.java b/src/main/java/com/ly/ckibana/handlers/ResolveIndexHandler.java index 4915cdd..b466f68 100644 --- a/src/main/java/com/ly/ckibana/handlers/ResolveIndexHandler.java +++ b/src/main/java/com/ly/ckibana/handlers/ResolveIndexHandler.java @@ -16,6 +16,8 @@ package com.ly.ckibana.handlers; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.ly.ckibana.configure.web.route.HttpRoute; import com.ly.ckibana.model.request.RequestContext; import com.ly.ckibana.service.CkService; @@ -23,6 +25,7 @@ import com.ly.ckibana.util.JSONUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -47,10 +50,15 @@ public List routes() { protected String doHandle(RequestContext context) throws Exception { List> ckIndices = new ArrayList<>(resolveCkIndices(context)); String esResponseBody = EsClientUtil.doRequest(context); - JSON.parseObject(esResponseBody).getJSONArray("indices").forEach(each -> { - //noinspection unchecked - ckIndices.add(JSON.parseObject(each.toString(), Map.class)); - }); + JSONObject jsonObject = JSON.parseObject(esResponseBody); + JSONArray indexArray; + if (jsonObject != null && (indexArray = jsonObject.getJSONArray("indices")) != null) { + for (Object each : indexArray) { + //noinspection unchecked + ckIndices.add(JSON.parseObject(each.toString(), Map.class)); + } + } + context.getHttpResponse().setStatus(HttpStatus.OK.value()); return JSONUtils.serialize(Map.of("indices", ckIndices)); }