@actuatorjs/actuatorjs
Version:
Core interfaces and classes for actuatorjs ecosystem
32 lines (31 loc) • 977 B
JavaScript
export class HealthCheck {
constructor(healthIndicators) {
this.healthIndicators = healthIndicators;
}
async getHealth() {
const components = {};
let overallStatus = "UP";
await Promise.all(this.healthIndicators.map(async (indicator) => {
try {
const result = await indicator.check();
components[indicator.getName()] = result;
if (result.status === "DOWN") {
overallStatus = "DOWN";
}
}
catch (error) {
components[indicator.getName()] = {
status: "DOWN",
details: {
error: error instanceof Error ? error.message : String(error),
},
};
overallStatus = "DOWN";
}
}));
return {
status: overallStatus,
components,
};
}
}