Skip to content

Commit

Permalink
Merge pull request #23 from qzhello/main
Browse files Browse the repository at this point in the history
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
  • Loading branch information
famosss authored Feb 6, 2024
2 parents e9c6007 + 716adcc commit 4e647df
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/com/ly/ckibana/handlers/ResolveIndexHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
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;
import com.ly.ckibana.service.EsClientUtil;
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;
Expand All @@ -47,10 +50,15 @@ public List<HttpRoute> routes() {
protected String doHandle(RequestContext context) throws Exception {
List<Map<String, Object>> 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));
}

Expand Down

0 comments on commit 4e647df

Please sign in to comment.