收藏
回答

使用http api监控job_id进度情况时出错?

const cloud = require('wx-server-sdk')
cloud.init(
  {
    // API 调用都保持和云函数当前所在环境一致
    env:cloud.DYNAMIC_CURRENT_ENV
  }
)
// 云函数入口函数
exports.main = async (event, context) => {
  let access_token=event.access_token
  let job_id = event.job_id
  console.log(access_token)//token可以成功获取
  console.log(job_id)//job_id可以成功获取


  let options = {
    url"https://api.weixin.qq.com/tcb/databasemigratequeryinfo?access_token=" + access_token,
    body: ({
      "env""xcxdemo-20c411",
      "job_id":job_id
    })
  }
  let res = await request(options)


  return res
}


使用https://api.weixin.qq.com/tcb/databasemigrateimport?access_token=ACCESS_TOKEN这个api




将json数据导入到云开发数据后,数据已经导入到数据库中,并且返回了job_id,我想监控任务的情况,云函数内容如上图,请问错在什么地方了,报错信息如下
捕捉到的错误信息 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID ffa56083-32ed-11eb-9e5c-5254008c2339, cloud function service error code -504002, error message ReferenceError: request is not defined
    at Runtime.exports.main [as handler] (:54908/var/user/index.js:23)
    at Runtime.handleOnce (:54908/var/runtime/node10/Runtime.engine.js:214)
    at Timeout.setTimeout [as _onTimeout] (:54908/var/runtime/node10/Runtime.engine.js:54)
    at ontimeout (:54908/appservice/timers.js:436)
    at tryOnTimeout (:54908/appservice/timers.js:300)
    at listOnTimeout (:54908/appservice/timers.js:263)
    at Timer.processTimers (:54908/appservice/timers.js:223); at cloud.callFunction api; 
    at new u (VM1195 WAService.js:2)
    at d (VM1195 WAService.js:2)
    at f (VM1195 WAService.js:2)
    at Function.success (VM1195 WAService.js:2)
    at h (VM1195 WAService.js:2)
    at VM1195 WAService.js:2
    at k (VM1195 WAService.js:2)
    at Function.<anonymous> (VM1195 WAService.js:2)
    at h (VM1195 WAService.js:2)
    at VM1195 WAService.js:2


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

1 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-11-30
    const request = require('request ')  学会看报错
    


    2020-11-30
    有用
    回复 1
    • Can
      Can
      发表于移动端
      2020-11-30
      不好意思,我傻了,刚才才看到是包的问题,谢谢
      2020-11-30
      回复
登录 后发表内容
问题标签