How to check http 200 status code in angular if its not available in the json response

前端 未结 3 818
抹茶落季
抹茶落季 2021-01-16 08:14

Auth Service

 logout() {
      return this.http.post(this.logOutApi, null);
    }

The status code doesn\'t show in the json response from t

3条回答
  •  臣服心动
    2021-01-16 08:30

    Other than 200 you get the status code in your error block. So here you will have to handle accordingly like below

     logout() {
            this.chk.logout().subscribe((res: any)=>{
              if(res.status == 200) //doesnt work{
              console.log(res);
              })
              }
            }, (error)=>{
              if (error.status === 500) {
                    alert('Server down please try after some time');
              }
              else if (error.status === 404) {
                   alert('Server down. Please try after some time');
             }
    
            });
        } 
    

    Hope this help

提交回复
热议问题