<p> <b>Output</b><br/> <span id="output"></span>
async function foo(){
let response;
try {
response = await fetch("https://httpstat.us/400"); // Try changing it to 200 to see a success response
if(response.ok) {
window.output.innerText = "All good ✅";
} else {
throw (
`Error: Response status ${response.status}`
);
}
} catch(e) {
window.output.innerText = e; // Logs "Error: Response status 400"
}
}
foo();
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.