私はフロントエンドでReactjs reduxを、バックエンドとしてRails APIを開発中です。javascriptから読み込み可能なエラーレスポンスを取得するapiを取得しますか?
は、だから今、私はAPIメソッドを取得して、APIを呼び出すが、問題は、私はこれが私の機能
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