You need to pass the second callback to the subscription method. This callback will be executed when an error occurs.
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) ); }
source share