I'm a bit stuck with the fetch API. This is a simple Login function
export default class LoginService {
async loginUser(u, p) {
return fetch(API_URL + '/users/authenticate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ 'username': u, 'password': p })
})
.then(response => response.json())
.catch(e => console.log(e))
}
}
When user is not found the in the backend return 400 bad request. How can I return the json object or the response status? Or maybe this practice is wrong?
Thank you!