0

I have this code

await fetch(url)
.then(response => {
    if(response.ok) return response.json()
    Promise.reject(response)
}).then(data => console.log(data))
.catch(async (response) => {
    console.log(response)
    await response.json().then(message => console.log(message))
})

And supposing that the response of the server is this.

res.status(400).json({ message: 'Error message' })

The console sends me the response but also sends an error on the fetch request. Did I do something wrong?

Mehdi
  • 385
  • 1
  • 12

0 Answers0