Javascript 未处理的承诺拒绝条带paymentIntent示例
我正在尝试使用node和express设置条带支付应用程序,如下所示: 如图所示,我在服务器端应用程序代码中创建了路由,并在html文件中插入了客户端代码。我正在尝试创建一个没有模板引擎的应用程序,只有html/css/javascript/nodeJavascript 未处理的承诺拒绝条带paymentIntent示例,javascript,node.js,stripe-payments,unhandled-promise-rejection,Javascript,Node.js,Stripe Payments,Unhandled Promise Rejection,我正在尝试使用node和express设置条带支付应用程序,如下所示: 如图所示,我在服务器端应用程序代码中创建了路由,并在html文件中插入了客户端代码。我正在尝试创建一个没有模板引擎的应用程序,只有html/css/javascript/node var response = fetch('/secret').then(function(response) { return response.json(); }).then(function(responseJson) { var
var response = fetch('/secret').then(function(response) {
return response.json();
}).then(function(responseJson) {
var clientSecret = responseJson.client_secret;
// Call stripe.confirmCardPayment() with the client secret.
});
我得到以下错误:
未经处理的拒绝承诺。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺
我不熟悉promises,也不确定这段代码的语法应该是什么。我可以补充一下吗
promise1.catch((error) => {
console.error(error);
});
是的,在末尾添加catch方法将捕获错误(拒绝承诺)。你的建议行得通
var response = fetch('/secret').then(function(response) {
return response.json();
}).then(function(responseJson) {
var clientSecret = responseJson.client_secret;
// Call stripe.confirmCardPayment() with the client secret.
}).catch(function(err) {
// Handle error
});
是的,您应该添加一个
.catch(…)
子句,但是什么是promise1
?