Skip to content

[ISSUE #13437] fix: readiness http response code 500 when not health #13644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: readiness http response code 500 when not health
  • Loading branch information
shalk committed Jul 25, 2025
commit 541c3901ceef75fe12af83011b8b8eec25649a2b
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.alibaba.nacos.console.paramcheck.ConsoleDefaultHttpParamExtractor;
import com.alibaba.nacos.console.proxy.HealthProxy;
import com.alibaba.nacos.core.paramcheck.ExtractorManager;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -62,8 +64,13 @@ public Result<String> liveness() {
* ready.
*/
@GetMapping("/readiness")
public Result<String> readiness() throws NacosException {
return healthProxy.checkReadiness();
public ResponseEntity<Result<String>> readiness() throws NacosException {
Result<String> ret = healthProxy.checkReadiness();
if (ret.getCode() == 0) {
return ResponseEntity.ok().body(ret);
} else {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ret);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ void testReadiness() throws Exception {
});

assertEquals("ready", result.getData());
assertEquals(200, response.getStatus());
}

@Test
void testReadinessFail() throws Exception {
when(healthProxy.checkReadiness()).thenReturn(Result.failure("fail"));

MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/v3/console/health/readiness");

MockHttpServletResponse response = mockMvc.perform(builder).andReturn().getResponse();
String actualValue = response.getContentAsString();

Result<String> result = new ObjectMapper().readValue(actualValue, new TypeReference<Result<String>>() {
});

assertEquals("fail", result.getMessage());
assertEquals(500, response.getStatus());

}
}

Loading