In angular documentation, it is stated that an HttpErrorResponse will be thrown for "non-successful HTTP status". (See here)
what are the non-successful statuses / non-successful status ranges for which an error will be thrown? Are there cases for which a response will be valid even if HTTP status is "non-successful"?
Context:
In my particular case I have an authentication service. there is a condition in RxJs pipe switchMap that checks if status code is in the range of 200-399. It seems like a redundant check. I was wondering if it can be removed.
this.http.get<UserDto>(ConstantUrlName.AUTHENTICATION_URL, {observe: 'response'}).pipe(switchMap((resp: HttpResponse<UserDto>) => {
const user = resp &&
resp.status >= 200 && resp.status < 400 &&
resp.body;
....
}))
According to comment by @jonrsharpe we can see the answer in the angular repository:
// ok determines whether the response will be transmitted on the event or // error channel. Unsuccessful status codes (not 2xx) will always be errors, // but a successful status code can still result in an error if the user // asked for JSON data and the body cannot be parsed as such. let ok = status >= 200 && status < 300;
Should probably be added in Angular's documentation.