My http service does not catch correctly some http errors. The catch method has 2 different response objects ( see below ).
private fireRequest(request: Request): Observable<any> {
return this.http.request(request)
.switchMap((response: Response) => {
const responseData = response.json() || [];
return Observable.of(responseData);
})
.catch((response: Response) => {
const res2 = response.json();
// filters http errors from status 0 errors
if (response.status && response.status > 0) {
const res = response.json();
return Observable.of<any>(res);
}
const unexpectedNetworkError = new
Error('commons.unexpected_network');
return Observable.throw(unexpectedNetworkError);
})
}
Strange error behaviour. ( even in chrome network tab i do not see the http body )
// catch 404 error
{
headers: Headers,
ok: false,
status: 0,
statusText : "",
type : 3,
url : null,
_body : ProgressEvent
}
Correct error behaviour
// catch 401 error
{
headers: Headers,
ok: false,
status: 401,
statusText : "Unauthorized",
type : 2,
url : http://api.service/users,
_body : { // json body}
}