POST
ユーザーのパスワードを更新するためにサーバーにリクエストを行うアクションがありますが、チェーンされた catch ブロックでエラーを処理できません。
return axios({
method: 'post',
data: {
password: currentPassword,
new_password: newPassword
},
url: `path/to/endpoint`
})
.then(response => {
dispatch(PasswordUpdateSuccess(response))
})
.catch(error => {
console.log('ERROR', error)
switch (error.type) {
case 'password_invalid':
dispatch(PasswordUpdateFailure('Incorrect current password'))
break
case 'invalid_attributes':
dispatch(PasswordUpdateFailure('Fields must not be blank'))
break
}
})
エラーをログに記録すると、次のように表示されます。
ネットワークタブを確認するとレスポンスボディは見えるのですが、なぜか値にアクセスできません!
私は無意識のうちにどこかで間違いを犯しましたか?別のリクエストからの他のエラーをうまく処理しているためですが、これを解決できないようです。