[英]axios get, if error (or 404), call axios post
I have an axios call to get a UPC from a dataset. 我有一个axios调用,用于从数据集中获取UPC。 If it's successful, I'll do something, if it's not found, call axios again to POST. 如果成功,我将做一些事情,如果找不到,请再次致电axios以进行POST。
This is what I have right now, but when it errors (404) when trying to run the get, I get a 422 error. 这就是我现在所拥有的,但是当尝试运行get时出错(404)时,我得到422错误。
axios.get('http://localhost:3000/api/products/findOne', {
"params": {
"filter": {
"where": {
"upc": product.upc
}
}
}
}).then(response => {
// UPC Found
}).catch(function(error) {
// UPC Not found
// Post UPC
axios.post('http://localhost:3000/api/products', {
//axios stuff here
}).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
});
});
I dont believe I am doing this correctly at all... Input? 我根本不相信我这样做正确...输入?
HTTP错误422表示无法处理的实体看起来像您所请求的API,如果找不到记录,则将其赋予422而不是404?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.