const transaction = await db.startTransaction()
try{
//写数据库代码略.........
await transaction.commit()
console.log(transaction succeeded
)
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
}catch(e) {
await transaction.rollback()
console.error(transaction error
, e)
return {
success: false,
error: e
}
}
//控制台结果,已经打印出 transaction succeeded,却抛出事务失败?
10:18:55.087 [本地调试]transaction succeeded uniCloud-aliyun/cloudfunctions
10:18:55.090 [本地调试]Error: 事务失败错误: transaction already commit
10:18:55.090 [本地调试] at new Promise (<anonymous>)
- 发布:2023-12-13 10:26
- 更新:2023-12-13 15:46
- 阅读:241
产品分类: uniCloud/App
示例代码:
操作步骤:
const transaction = await db.startTransaction()
try{
//写数据库代码略.........
await transaction.commit()
console.log(transaction succeeded
)
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
}catch(e) {
await transaction.rollback()
console.error(transaction error
, e)
return {
success: false,
error: e
}
}
//控制台结果,已经打印出 transaction succeeded,却抛出事务失败?
10:18:55.087 [本地调试]transaction succeeded uniCloud-aliyun/cloudfunctions
10:18:55.090 [本地调试]Error: 事务失败错误: transaction already commit
10:18:55.090 [本地调试] at new Promise (<anonymous>)
const transaction = await db.startTransaction()
try{
//写数据库代码略.........
await transaction.commit()
console.log(transaction succeeded
)
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
}catch(e) {
await transaction.rollback()
console.error(transaction error
, e)
return {
success: false,
error: e
}
}
//控制台结果,已经打印出 transaction succeeded,却抛出事务失败?
10:18:55.087 [本地调试]transaction succeeded uniCloud-aliyun/cloudfunctions
10:18:55.090 [本地调试]Error: 事务失败错误: transaction already commit
10:18:55.090 [本地调试] at new Promise (<anonymous>)
预期结果:
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
实际结果:
return {
success: false,
error: e
}
return {
success: false,
error: e
}
bug描述:
const transaction = await db.startTransaction()
try{
//写数据库代码略.........
await transaction.commit()
console.log(transaction succeeded
)
return {
success: true,
order_no: order_no,
total_fee:orderHead.total_fee
}
}catch(e) {
await transaction.rollback()
console.error(transaction error
, e)
return {
success: false,
error: e
}
}
//控制台结果,已经打印出 transaction succeeded,却抛出事务失败?
10:18:55.087 [本地调试]transaction succeeded uniCloud-aliyun/cloudfunctions
10:18:55.090 [本地调试]Error: 事务失败错误: transaction already commit
10:18:55.090 [本地调试] at new Promise (<anonymous>)
本地调试:uni-h5.es.js:19612
POST http://127.0.0.1:7000/cloudfunctions/my-save-order 500 (Internal Server Error)
2***@qq.com (作者)
Error: 事务失败错误: transaction already commit
2023-12-13 15:46
2***@qq.com (作者)
回复 2***@qq.com: 谢谢,放后面错误被屏蔽了
2023-12-14 11:41