Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active April 3, 2019 09:24
Show Gist options
  • Save gladchinda/36f46aadcf316e604ae67e1db43d0c5f to your computer and use it in GitHub Desktop.
Save gladchinda/36f46aadcf316e604ae67e1db43d0c5f to your computer and use it in GitHub Desktop.
const fetchTempForCity = city => {
return fetch(`${API_URL}&q=${encodeURIComponent(city)}`)
.then(response => response.json())
.then(data => [ city, data.main.temp || null ])
// Attach a `.catch()` handler for graceful rejection handling
.catch(() => [ city, null ]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment