收藏
回答

调用云函数失败?

两个云函数有一个调用成功,另一个报错,下面为调用失败的云函数。

// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()

// 云函数入口函数
const db = cloud.database()
const MAX_LIMIT = 100
exports.main = async (event, context) => {
  const new_name = event.a
  // 先取出集合记录总数
  const countResult = await db.collection(new_name).count()
  const total = countResult.total
  // 计算需分几次取
  const batchTimes = Math.ceil(total / 100)
  // 承载所有读操作的 promise 的数组
  const tasks = []
  for (let i = 0; i < batchTimes; i++) {
    const promise = db.collection(new_name).skip(i * MAX_LIMIT).limit(MAX_LIMIT).get()
    tasks.push(promise)
  }
  // 等待所有
  return (await Promise.all(tasks)).reduce((acc, cur) => {
    return {
      data: acc.data.concat(cur.data),
      errMsg: acc.errMsg,
    }
  })
}


wx.cloud.callFunction({
      name:'tichu',
      data: {
        a: 'allplayers'
      },
      success: res => {
          console.log(res)
      },
      fail :err => {console.log(err)}
  });
/*
 捕获的错误为
Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: Error: collection.count:fail -501003 exceed request limit. [ResourceUnavailable.ResourceOverdue] Resource has expired. Please renewal fee, but if the problem cannot be solved, contact us.
    at Object.toSDKError (:43397/var/user/node_modules/wx-server-sdk/index.js:8064)
    at Object.checkError (:43397/var/user/node_modules/wx-server-sdk/index.js:1421)
    at :43397/var/user/node_modules/wx-server-sdk/index.js:1557
    at processTicksAndRejections (:43397/appservice/internal/process/task_queues.js:97) (callId: 1669034947614-0.22814895692167214) (trace: 20:49:7 start->20:49:7 app show->20:49:8 system error (Error: errCode: -504002 functions execute fail | errMsg: Error: collection.count:fail -501003 exceed request limit. [ResourceUnavailable.ResourceOverdue] Resource has expired. Please renewal fee, but if the problem cannot be solved, contact us.
    at Object.toSDKError (:43397/var/user/node_modules/wx-server-sdk/index.js:8064)
    at Object.checkError (:43397/var/user/node_modules/wx-server-sdk/index.js:1421)
    at :43397/var/user/node_modules/wx-server-sdk/index.js:1557
    at processTicksAndRejections (:43397/appservice/internal/process/task_queues.js:97)), abort)
    at k (VM30 WAService.js:1)
    at VM30 WAService.js:1
*/


本地调试的错误为:

[error] 函数执行失败(耗时 107ms) Error: collection.count:fail -501003 exceed request limit. [ResourceUnavailable.ResourceOverdue] Resource has expired. Please renewal fee, but if the problem cannot be solved, contact us.

    at Object.toSDKError (/Users/admin/Desktop/tichu-opentest/cloudfunctions/tichu/node_modules/wx-server-sdk/index.js:8064:19)

    at Object.checkError (/Users/admin/Desktop/tichu-opentest/cloudfunctions/tichu/node_modules/wx-server-sdk/index.js:1421:23)

    at /Users/admin/Desktop/tichu-opentest/cloudfunctions/tichu/node_modules/wx-server-sdk/index.js:1557:33

    at processTicksAndRejections (node:internal/process/task_queues:96:5)


回答关注问题邀请回答
收藏

1 个回答

  • Xxxxxy_112
    Xxxxxy_112
    2022-12-02

    解决了没有呢?我这边也遇到一样的问题

    2022-12-02
    有用
    回复 1
    • 牛野
      牛野
      2022-12-06
      到云函数里把环境写死
      2022-12-06
      回复
登录 后发表内容