<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();

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.