Я работаю над редукцией Reactjs на front-end и Rails api в качестве back-end.Как получить читаемый ответ об ошибке из javascript Fetch api?
Так что теперь я называю апи с Fetch метод апи, но проблема в том, что я не могу получить читаемое сообщение об ошибке, как то, что я получил внутри сети вкладок
это моя функция
export function create_user(user,userInfoParams={}) {
return function (dispatch) {
dispatch(update_user(user));
return fetch(deafaultUrl + '/v1/users/',
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify(userInfoParams)
})
.then(function(response) {
console.log(response);
console.log(response.body);
console.log(response.message);
console.log(response.errors);
console.log(response.json());
dispatch(update_errors(response));
if (response.status >= 400) {
throw new Error("Bad response from server");
}
})
.then(function(json){
console.log("succeed json re");
// We can dispatch many times!
// Here, we update the app state with the results of the API call.
dispatch(update_user(json));
});
}
}
Но когда пришли ошибки я не могу понять, как получить читаемое сообщение ответа, как я получил, когда я проверяю свои вкладки в сети моего браузера
Так вот что я получил от сетевых вкладок, когда у меня появились ошибки.
Моя консоль
Это мои рельсы код
def create
user = User.new(user_params)
if user.save
#UserMailer.account_activation(user).deliver_now
render json: user, status: 201
else
render json: { errors: user.errors }, status: 422
end
end
Но я не могу узнать, как я могу получить, что внутри моей функции
Спасибо !
Можете ли вы опубликовать свой вывод console.log? – Aus