title: Cannot read property 'error' of undefined. What's the problem?
body: <p>My REST API reasons this: <code>{"error":"Auth failed. User does not exist"}</code>.
  I try save this error to my state using setState in React, but I have a this error: Cannot read property 'error' of undefined. What's the problem?</p>
  
  <pre><code>export const login = user =&gt;
    axios
      .post('http://localhost:3000/api/users/login', {
        login: user.login,
        password: user.password,
      })
      .then(res =&gt; {
        localStorage.setItem('userToken', res.data.token);
        return res.data.token;
      })
      .catch(err =&gt; {
        console.log(err);
      });
  </code></pre>
  
  <p>Function in React.js:</p>
  
  <pre><code>  onSubmit(e) {
      e.preventDefault();
  
      const user = {
        login: this.state.login,
        password: this.state.password,
      };
  
      login(user).then(res =&gt; {
        if (!res.error) { // &lt;- this error: TypeError: Cannot read property 'error' of undefined
          this.props.history.push(`/dashboard`);
        } else {
          this.setState({ error: res.error });
        }
      });
    }
  </code></pre>
  
  <p>This is my backend code:</p>
  
  <pre><code>    // Login Action
  ...
                return res.status(200).json({
                  message: 'Auth successful',
                  token,
                });
              }
              res
                .status(400)
                .json({ error: 'Auth failed. The password is incorrect.' });
            } else {
              res.status(400).json({ error: 'Auth failed. User does not exist' });
            }
          })
          .catch(err =&gt; {
            res.status(400).json({ error: err });
          });
      };
  </code></pre>