简体   繁体   English

我的功能正常出现422错误

[英]I'm getting a 422 error for a function that works

I'm building a bucket-list application, and I've included a function to allow users to delete items/documents from their bucket list/the database. 我正在构建一个存储桶列表应用程序,并且包括了一个允许用户从其存储桶列表/数据库中删除项目/文档的功能。 When the function is called, I receive an HTTP 422 Unprocessable Entity error, leading me to believe the function does not work. 调用该函数时,我收到一个HTTP 422不可处理实体错误,使我相信该函数不起作用。 However, when I refresh the page, the data has been successfully deleted from the database. 但是,当我刷新页面时,数据已成功从数据库中删除。

Here is the function for deleting the item on the list (the document from the database): 这是删除列表中的项目(数据库中的文档)的功能:

  handleDelete = id => {
    API.deleteItemFromList(this.props.match.params.id)
      .then(res => console.log(res.data))
      .catch(err => console.log(err));
  };

And here is the code for the api: 这是api的代码:

  deleteItemFromList: function(id) {
    return axios.delete("/api/bucketList/" + id);
  }
};

So basically, the function does work, but it doesn't work, and I don't understand why. 因此,基本上,该功能可以工作,但不能工作,我也不明白为什么。 And I'd like to be able to delete the item from the list without getting any error at all. 而且我希望能够从列表中删除该项目,而不会出现任何错误。

I'm pretty sure I've supplied all the necessary code, but if I've left something out, or if there's something else you need or would like to see, let me know. 我很确定我已经提供了所有必要的代码,但是如果我遗漏了一些东西,或者还有其他需要或希望看到的内容,请告诉我。

Many thanks in advance! 提前谢谢了!

The error you're getting is TypeError: req.json is not a function . 您得到的错误是TypeError: req.json is not a function You'll need to change req.json to res.json . 您需要将req.json更改为res.json

It's the small stuff that'll get ya. 这是小东西,你会得到的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM