async await function try catch not returning error

Viewed 13

Im trying to make a simple weather app to learn how to work with api's and i cant seem to return errors in a usable way. here's the code

async function getWeather() {
    try {
        const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${citySearch}&APPID=65d57bbf714db2778c05eb37107c6320&units=metric`)
        let weatherData = await response.json()
        weatherObject = await weatherData
    } catch (err) {
        console.log('error')
        console.log(err)
    }
}

im trying to test it by entering the city name in a text input field incorrectly but when i do i never get the error console.log. The error does appear in my console saying 404 but nut no console.log message saying error.

If theres anymore info needed please let me know this is my first time posting a question

0 Answers
Related