How to do it...

  1. Open your command-line application and navigate to your workspace.
  2.  Create a new folder named 3-07-handle-errors-promise-catch.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  1. Create a main.js file with a main function that creates an object named rocket:
export function main() { 
 
  console.log('Before promise created'); 
 
  const rocket = {}; 
 
  console.log('After promise created'); 
} 
  1. Create a function addBoosters that throws an error:
function addBoosters (rocket) { 
  throw new Error('Unable to add Boosters'); 
} 
  1. Create a function performGuidanceDiagnostic that returns a promise that rejects an error:
function performGuidanceDiagnostic (rocket) { 
  return new Promise(function (resolve, reject) { 
    reject(new Error('Unable to finish guidance diagnostic')); 
  }); 
} 
  1. Use Promise.resolve to pass the rocket object to these functions, and chain a catch off each of them:
export function main() { 
 
  console.log('Before promise created'); 
 
  const rocket = {}; 
  Promise.resolve(rocket).then(addBoosters)
.catch(console.error);
Promise.resolve(rocket).then(performGuidanceDiagnostic)
.catch(console.error); console.log('After promise created'); }
  1. Start your Python web server and open the following link in your browser: 
    http://localhost:8000/.
  1. You should see the following output: