title: Error when I delete a user: Unhandled Rejection (TypeError): Cannot read property 'error' of undefined
body: <p>I'm trying to delete a user inside my application, when I click the button that calls the delete function I'm getting this wrong,
  Unhandled Rejection (TypeError): Cannot read property 'error' of undefined.
  but when I update the page the user is deleted.
  <a href="https://i.stack.imgur.com/aceqk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aceqk.png" alt="enter image description here" /></a></p>
  <pre><code>export const deleteUser = (clientId, userId, token) =&gt; {
      return fetch(`${API}/user/${clientId}/${userId}`, {
          method: 'DELETE',
          headers: {
              Accept: 'application/json',
              'Content-Type': 'application/json',
              Authorization: `Bearer ${token}`
          }
      })
          .then(response =&gt; {
              return response.json();
          })
          .catch(err =&gt; console.log(err));
  };
  
  const destroy = clientId =&gt; {
          deleteUser(clientId, user._id, token).then(data =&gt; {
              if(data.error) {
                  console.error(data.error);
              }else{
                  loadUser();
              }
          })
      }
  
  &lt;button onClick={()=&gt; destroy(person._id)} className=&quot;btn btn-danger btn-sm&quot;&gt;Deletar&lt;/button&gt; 
  </code></pre>
  <p>//Node my backend.</p>
  <pre><code>exports.remove = (req, res) =&gt;{
   
      User
      .findByIdAndRemove(req.params.clientId)
      .exec()
      .then(doc =&gt; {
          if(!doc) { return res.status(404).end();}
          return res.status(204).end();
      }) 
      .catch(err =&gt; next(err));
  }
  </code></pre>