DEV Community


Posted on


Handling errors with Fetch

Enhancement of one of my previous post Swiss&Fetch.
Here is a way to handling errors when fetch fails

async function fetchUsers(numUsers) {
    const response = await fetch(`${numUsers}`)
    return await response.json()

async function displayUsers(numUsers) {
    let data = await fetchUsers(numUsers).catch(e => console.log(e.message))
    data && listusers.setAttribute("users", JSON.stringify(data.results))

Top comments (0)

50 CLI Tools You Can't Live Without

The top 50 must-have CLI tools, including some scripts to help you automate the installation and updating of these tools on various systems/distros.