// Error handling while fetching API
const url = "http://dummy.restapiexample.com/api/v1/employee/40";
fetch(url) //404 error
.then( res => {
if (res.ok) {
return res.json( );
} else {
return Promise.reject(res.status);
}
})
.then(res => console.log(res))
.catch(err => console.log('Error with message: ${err}') );