Skip to content

Commit 52769da

Browse files
Alexandru RaileanuMattia Vianelli
authored andcommitted
DSC-2868 fix(health): parse fetch Response body in healthCheck endpoint
The healthCheck function was migrated from axios to native fetch but the .then() handler still sends the raw Response object instead of the parsed body. Express serializes the opaque Response as {}. Fix: call response.json() to extract the body before sending. Also add null-safe error handling for network errors where error.response is undefined. Ref: DEV-2280 (cherry picked from commit 10fc4b0b7dc0e6f4456a78177382e94d63d39d7c)
1 parent 6abcc93 commit 52769da

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,12 @@ function healthCheck(req, res) {
719719
const baseUrl = `${REST_BASE_URL}${environment.actuators.endpointPath}`;
720720
fetch(baseUrl)
721721
.then((response) => {
722-
res.status(response.status).send(response);
722+
return response.json().then((data) => {
723+
res.status(response.status).send(data);
724+
});
723725
})
724726
.catch((error) => {
725-
res.status(error.response.status).send({
727+
res.status(error?.response?.status || 503).send({
726728
error: error.message,
727729
});
728730
});

0 commit comments

Comments
 (0)