The Angular documentation on the new HttpClient https://angular.io/guide/http has a section "Getting error details" where they show an example like below. I have modified to comments to document my observations which basic error classes end up where.
http
.get<ItemsResponse>('/api/items')
.subscribe(
data => {...},
(err: HttpErrorResponse) => {
if (err.error instanceof Error) {
// we never seem to get here
console.log('An error occurred:', err.error.message);
} else {
// no network connection, HTTP404, HTTP500, HTTP200 & invalid JSON
console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
}
}
);
So at least 3 totally different categories of errors (network, http, response parsing) come in on a single channel and for each type one has to search for the actual reason in another part of HttpErrorResponse.
One can identify only one category, the HTTP errors through the standard error codes. But the other two types?
When I pull my network plug I get the extremely telling err.message = "Http failure response for (unknown url): 0 Unknown Error." Very descriptive.
When the new internal JSON parsing fails it says that there is a syntax error - but not at what position/character (as returned by JSON.parse()). See also here
What about other errors like timeouts, etc.?
Where can I find documentation on this? Has anyone figured out a way to generally analyse this so one can give meaningful messages to the user?
Angular 5.2 in Chrome on Win, Backend: ASP.NET4.6.1 pure IHttpHandler