Check http status at the angle

Asked

Viewed 277 times

1

I have the following code, I need to check the status that the server returns to the Webapp, I have the following code:

this.http.post (this.url,json) 

    .subscribe ( 
          res => { 
            console.log(res);
          }, 
          (err: any) => { 
            console.log('raw error =>', err);
          } 
        );}
  • What version of Angular? The latest ones ( >6) have a different use to get the return status

  • Perhaps that interests you: Httpclient - Getting error Details

1 answer

1


Do it like this:

this.http.post (this.url,json, {observe: 'response'})     
    .subscribe ( 
          res => { 
            console.log(res);
            console.log(res.status);
          }, 
          (err: any) => { 
            console.log('raw error =>', err);
          } 
        );}
  • is giving error in the part {note: 'Response'}, why?

  • Try the constructor (http:Httpclient)

  • Thank you very much friend. It worked.

  • Mark the answer as right! Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.