【发布时间】:2021-11-12 01:08:54
【问题描述】:
向我的节点服务器发送 axios 请求后,我如何响应“拒绝”Axios 路由/请求并最终出现在客户端代码的“catch()”中?我知道“res.send(data)”或“res.json(data)”将解析为 promise 的“then()”。有什么我可以回应的会拒绝它吗?
axios.post('/edit-item', {_id: id, updateText: editInput.value, author: author}).then((response) => {
e.target.parentElement.parentElement.children[3].innerHTML = `${response.data}`
}).catch(() => {
//I want to end up here by responding with something from the server
})
【问题讨论】:
-
任何 HTTP error 状态码?
-
你也可以明确说你想把哪些HTTP状态码视为错误,axios-http.com/docs/handling_errors
-
会像这样回应-“res.send(404)”拒绝承诺吗?
-
我想明确表示我是故意试图抛出一个错误。如您所见,我正在将数据发送到我的快递服务器。如果“作者”字段与某条数据不匹配,我希望承诺拒绝并最终出现在“axios.get()”方法的“catch()”中。
标签: javascript express axios