Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to find network disconnected issue. I have tried multiple ways. Still i didn't get the solution. I could not achieve with status code.


Here is my sample code:

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;
      }
    }

     );


Can any one solve my problem ?. Thanks in Advance.

What I have tried:

I want to display Network Disconnected Alert. I want to get the Error in console. But, i did not get the solution.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900