简体   繁体   English

如何解决未捕获(承诺)错误?

[英]how to solve Uncaught (in promise) error?

I am getting this error in inspect->console我在检查->控制台中收到此错误

enter image description here在此处输入图像描述

this is my code, getting error in line - ProductHelper.create(data)这是我的代码,出现错误 - ProductHelper.create(data)

      if (this.props.data !== undefined) {
            data.product_id = this.props.data.product_id;
            data.is_active = is_active;
            ProductHelper.update(data, this.props.data.product_id)
                .then((data) => {
                    if (data.code == 200) {
                        alert("Product successfully updated!");
                        this.props.getProducts();
                        this.props.setVisibility(false);
                    } else {
                        throw "Incorrect seller id";
                    }
                })
                .catch((err) => {
                    throw err;
                });
        } else {
            ProductHelper.create(data)
                .then((data) => {
                    if (data.code == 200) {
                        alert("Product successfully created!");
                        this.props.getProducts();
                        this.props.setVisibility(false);
                    } else if (data.code == 401) {
                        alert("Your product limit has exceeded!");
                    } else {
                        throw "error";
                    }
                })
                .catch((err) => {
                    throw err;
                });
        }
    } catch (err) {
        alert("Error creating. Try Again Later!");
        console.log(err);
    }
}

what should i do?我应该怎么办?

I think the promise is failing and not able to find an error block.我认为 promise 失败并且无法找到错误块。 You will have to add a catch statement with the promise.您必须使用 promise 添加一条 catch 语句。

promise
.then((res) => {})
.catch(err => console.log(err));

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

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