Я пытаюсь найти проблему с отключенной сетью. Я пробовал несколько способов. Тем не менее я не получил решение. Я не мог достичь с кодом состояния.
Вот мой пример кода:
var headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Bearer ' + this.token);
this.http.get('http://someurl/'+userId,{headers:headers})
.map(res => res.json())
.subscribe(
data => {
console.log(data);
},
error => {
console.log(error);
if(error.status == 500) {
this.dashResponse = false;
this.notFoundResponse = false;
this.serverErrorResponse = true;
}
else if(error.status == 404)
{
this.dashResponse = false;
this.notFoundResponse = true;
this.serverErrorResponse = false;
}
else if(error.status == 401)
{
this.router.navigate(['/login']);
alert('Un Authorized');
this.refresh();
}
else
{
this.dashResponse = false;
this.notFoundResponse = false;
this.serverErrorResponse = true;
}
}
);
Может ли кто-нибудь решить мою проблему? Заранее спасибо.