Angular 2 HTTP get handling 404 error Angular 2 HTTP get handling 404 error angularjs angularjs

Angular 2 HTTP get handling 404 error


You need to pass a second callback to the subscribe method. This callback will execute when there is an error.

function handleError(error) {  console.log(error)}fetchData(){  return this.http.get('https://jsonplaceholder.typicode.com/psts/6')      .map(          (res) => res.json()      )      .subscribe(        (data) => console.log(data),        (error) => handleError(error)  );}


There is no problem in your code, the URL itself is giving a 404