Everytime a http requests fails in my Angular project (e.g. ‘service not available’ or ‘CORS policy’) I’m receiving a HttpErrorResponse with { status: 0, statusText: 'Unknown Error', ...}
But I would like to get more details to give additional information to the user.
When inspecting the developer console of the browser I see some more information like net::ERR_CONNECTION_REFUSED (service unavailable) and net::ERR_FAILED (CORS policy). But I have no idea how to get access to this information within my code.
console output of the browser in case the service is down

console output of the browser in case the CORS policy blocks the request

I tried to get the information in this way
try {
this.http.get<MyResponseType[]>(`${this.HOST}/path/to/resource?param=${param}`)
.pipe(
catchError((err) => of(`I caught: ${err.message}`))
).subscribe(
(config) => console.log(config)
);
} catch (e:any) {
console.log("exception was thrown");
console.warn(e);
}
Everything I got was HttpErrorResponse with { status: 0, statusText: 'Unknown Error', ...}.
Has anyone an idea how to get more details?
To be clear: I’m not interested in how to solve the problems shown in the screenshots. I want to know how to handle the errors in a better way.
Thanks a lot!
