DEV Community

Discussion on: Error when I delete a user: Unhandled Rejection (TypeError): Cannot read property 'error' of undefined

Collapse
 
hnicolas profile image
Nicolas Hervé

In the deleteUser function, if fetch() or response.json() throw an error, it is swallowed by the catch clause. In this case data value in the then clause of the destroy function is undefined and you can't call data.error.

Collapse
 
hnicolas profile image
Nicolas Hervé

I think your problem is that your api call returns an empty body and response.json() fails on responses with an empty body.