Javascript “如何修复错误”;无法读取属性';状态文本';“未定义”的定义;

Javascript “如何修复错误”;无法读取属性';状态文本';“未定义”的定义;,javascript,redux,axios,Javascript,Redux,Axios,因此,我在尝试删除webapp中的“教育/体验”字段时遇到此错误。但当我按delete键时,它会抛出一个错误: Unhandled Rejection (TypeError): Cannot read property 'statusText' of undefined 当它试图发送有效载荷时就会发生这种情况。以下是导致错误的代码: 161 | } catch (err) { 162 | dispatch({ 163 | type: PROFILE_ERROR, >

因此,我在尝试删除webapp中的“教育/体验”字段时遇到此错误。但当我按delete键时,它会抛出一个错误:

Unhandled Rejection (TypeError): Cannot read property 'statusText' of undefined
当它试图发送有效载荷时就会发生这种情况。以下是导致错误的代码:

  161 | } catch (err) {
  162 |   dispatch({
  163 |     type: PROFILE_ERROR,
> 164 |     payload: { msg: err.response.statusText, status: err.response.status },
  165 | ^    });
  166 |   console.log(err.response);
  167 | }
以下是删除操作文件:

export const deleteEducation = (id) => async (dispatch) => {
  try {
    const res = axios.await(`/api/profile/education/${id}`);

    dispatch({
      type: UPDATE_PROFILE,
      payload: res.data,
    });

    dispatch(setAlert('Education Deleted', 'success'));
  } catch (err) {
    dispatch({
      type: PROFILE_ERROR,
      payload: { msg: err.response.statusText, status: err.response.status },
    });
    console.log(err.response);
  }
};
以下是删除功能的API代码:

// @route   DELETE api/profile/:edu_id
// @desc    Delete education from profile
//@access  Private
router.delete('/education/:edu_id', auth, async (req, res) => {
  try {
    const profile = await Profile.findOne({ user: req.user.id });
    const removeIndex = profile.education
      .map((item) => item.id)
      .indexOf(req.params.edu_id);
    profile.education.splice(removeIndex, 1);

    await profile.save();
    res.json({ msg: 'Education Deleted' });
  } catch (err) {
    console.log(err.message);
    res.status(500).send('Server Error');
  }
});

我真的很难理解redux,所以我不知道如何修复它。

在您的删除操作文件中

将第3行替换为


const res=wait axios.delete(`/api/profile/education/${id}`)

通常,像这样的错误意味着您试图访问一个不存在的对象的属性,所以首先我要打印错误对象,看看它有什么。尝试在错误行之前记录对象。
err.response
未定义