Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未处理的承诺拒绝条带paymentIntent示例_Javascript_Node.js_Stripe Payments_Unhandled Promise Rejection - Fatal编程技术网

Javascript 未处理的承诺拒绝条带paymentIntent示例

Javascript 未处理的承诺拒绝条带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

我正在尝试使用node和express设置条带支付应用程序,如下所示:

如图所示,我在服务器端应用程序代码中创建了路由,并在html文件中插入了客户端代码。我正在尝试创建一个没有模板引擎的应用程序,只有html/css/javascript/node

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