Advertisement
karlakmkj

Using .catch() with promises

Dec 28th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //inventory of sunglasses in library.js file is to 0 - refer the code in previous paste
  2. //so the order shouldn’t go through
  3.  
  4. const {checkInventory} = require('./library.js');
  5.  
  6. const order = [['sunglasses', 1], ['bags', 2]];
  7.  
  8. const handleSuccess = (resolvedValue) => {
  9.   console.log(resolvedValue);
  10. };
  11.  
  12. const handleFailure = (rejectReason) => {
  13.   console.log(rejectReason);
  14. };
  15.  
  16. // Write your code below:
  17. checkInventory(order)
  18. .then(handleSuccess)
  19. .catch(handleFailure)
  20.  
  21. /*
  22. Output will show:
  23. $ node app.js
  24. We're sorry. Your order could not be completed because some items are sold out.
  25. $
  26. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement