DzITC
DzITC

Reputation: 879

Django Rest Framework & React Js ( Axios API Request ): After Incorrect authentication attempt, api returns 400

I'm creating a login system and basically, I have two inputs, one for username and the other for password. So when the user enters the correct credentials the API returns 200 response with some data but after incorrect credentials the django-rest-framework marks the request as 400 Bad Request and returns the response with 400 status code and no data, but this happens only when I'm sending a request from react js, after trying bad credentials from postman, the API returns:

{
    "non_field_errors": [
        "Incorrect credentials"
    ]
} 

My Axios code:

 axios.post('http://192.168.0.29:8000/api/auth/login', {
      headers: {
        'Content-Type': 'application/json'
      },
      username: username,
      password: password
    })
    .then((response) => {
      console.log(response.data);
    })
    .catch(err => {
      console.log(err.data)
      alert('zjbs eroras')
    });

  }

Upvotes: 0

Views: 451

Answers (1)

DzITC
DzITC

Reputation: 879

I displayed error messages with :

console.log(err.response.data)

Upvotes: 1

Related Questions