Skip to main content

Day 11 - Exceptions, More Looping

Housekeeping

  • Marking delayed due to course outline update season

1. Handing Exceptions with async/await

Slides - Handling Exceptions

Demo: Adding error handling to JSON Placeholder

Activity: Add error handling to zoo example

Instructions

  1. Copy the sample code into your workspace
  2. Edit the URL so that the domain is non-existent:
    https://zoo-animal-api.herokuapp.com/animals/rand/10
    Break the domain:
    https://zoo-animal-BROKEN-api.herokuapp.com/animals/rand/10
  3. Add a try/catch that outputs an error to the user instead of a blank page;
  4. Fix the domain and instead break the path:
    https://zoo-animal-api.herokuapp.com/animals/rand/10
    Break the path:
    https://zoo-animal-api.herokuapp.com/BROKEN/rand/10
  5. Throw a custom error by testing for a true value on response.ok so that the page displays a custom “404 Not Found” error for the user.

2. Array.forEach() and Higher Order Array Methods

Slides - Higher Order Array Methods

Demo: Looping through JSON Placeholder

  • Starter Code

Activity: Looping through zoo example

Instructions

  1. Copy the sample code into your workspace;
  2. Using Array.forEach() refactor the starter code so that all 10 zoo animals are displayed instead of one random one.

Lab Time


Prep

Errors and Exceptions

Looping with higher order functions