window.onload = () => {
fetch("https://www.w3schools.com/nodejs/incorrecturl")
.then(res => res.json())
.then(data => console.log(data))
.catch(error => alert(error.toString())) // Here i need proper error message, instead of "failed to fetch".
}
var myRequest = new Request('https://www.w3schools.com/nodejs/incorrecturl');
fetch(myRequest).then(function(response) {
console.log(response.status);
});
fetch('https://www.w3schools.com/nodejs/incorrecturl').then(function(response) {
console.log(response.status);
});