I am developing a simple healthcheck page on my Angular application. On the page I perform all the healthchecks like this:
performHealthchecks() {
for (const [service, url] of Object.entries(this.endpoints)) {
this.logger.debug(`Checking health for ${service}`);
this.http.get(url, { responseType: 'text', observe: 'response' }).toPromise()
.then((response: HttpResponse<any>) => {
this.logger.debug(`${service} HEALTHY`);
}).catch((err: HttpErrorResponse) => {
this.logger.error(`${service} UNHEALTHY: ${err}`);
});
}
}
My problem is that instead of an HttpErrorResponse
I get a string with only "Unknown Error". But on the browser console I do see the actual error, with a console log from zone.js:
http://localhost:3000/ net::ERR_CONNECTION_REFUSED zone.js:2680
I need to know the response status code to correctly identify the problem with the service, if any, but at the moment I cannot as I do not get any status code in the catch but only a useless string.