Annie is developing a web application with one of the functionalities as getting the list of courses available for a particular semester. But the application returned an error as follows :
“fetchapi.html:11 Uncaught (in promise) TypeError: Failed to fetch”. A part of the code she had written is as follows :
async function myFetchAPI() {
let response = await fetch('http://localhost:4400/courses');//Line1
if (response.ok) {
let json = await response.json();//Line2
console.log(json)
}
else {
console.log("HTTP-Error: " + response.status);
}
}
myFetchAPI();//Line3
Which of the lines can be modified such that a user-friendly error message can be recorded on the console?
Line3.
myFetchAPI(function(error){ console.log(error)});Line2.
let json = await response.json().catch(error);Line1.
let response = new Promise(function(resolve, reject){ resolve(courses)});Line3.
myFetchAPI().catch(function(error){ console.log("HTTP-Error: " + error.message) });To get all Infosys Certified JavaScript Developer Exam questions Join Telegram Group https://rebrand.ly/lex-telegram-236dee