db.collection(collection).doc(userInfo.uid).set({ data: userInfo }).then(e => { console.log(e) }). catch (er => { console.log( '云函数保存用户信息出错:' , er) }) |
2019-11-14T05:26:14.923Z 云函数保存用户信息出错: { Error: errCode: -501001 resource system error | errMsg: signature is expired;
at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6395:28)
at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6447:16)
at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1678:23)
at DocumentReference.<anonymous> (/var/user/node_modules/wx-server-sdk/index.js:1538:41)
at step (/var/user/node_modules/tslib/tslib.js:136:27)
at Object.next (/var/user/node_modules/tslib/tslib.js:117:57)
at fulfilled (/var/user/node_modules/tslib/tslib.js:107:62)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) errCode: -501001, errMsg: 'signature is expired; ' }
2019-11-14T05:49:16.209Z 云函数保存用户信息出错: { Error: errCode: -501001 resource system error | errMsg: signature is expired;
at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6395:28)
at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6447:16)
at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1678:23)
at DocumentReference.<anonymous> (/var/user/node_modules/wx-server-sdk/index.js:1538:41)
at step (/var/user/node_modules/tslib/tslib.js:136:27)
at Object.next (/var/user/node_modules/tslib/tslib.js:117:57)
at fulfilled (/var/user/node_modules/tslib/tslib.js:107:62)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) errCode: -501001, errMsg: 'signature is expired; ' }
2019-11-15T02:48:06.867Z 云函数保存用户信息出错: { Error: errCode: -501001 resource system error | errMsg: signature is expired;
at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6395:28)
at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6447:16)
at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1678:23)
at DocumentReference.<anonymous> (/var/user/node_modules/wx-server-sdk/index.js:1538:41)
at step (/var/user/node_modules/tslib/tslib.js:136:27)
at Object.next (/var/user/node_modules/tslib/tslib.js:117:57)
at fulfilled (/var/user/node_modules/tslib/tslib.js:107:62)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) errCode: -501001, errMsg: 'signature is expired; ' }
一点都不稳定嘛,怎么敢用?
没人处理解释,我就天天发。
我也遇到过这种问题,经过多次调试找到了 因为储存到数据库中的数据类型不能被数据库正确储存导致的出错(我储存的是arrayBuffer对象类型)。检查下储存的数据类型
看着代码应该没问题
exports.main = async(event, context) => {
const wxContext = cloud.getWXContext()
const db = cloud.database()
const collection = 'user'
•
let userInfo = event.userInfo.data
console.log(event)
if (!userInfo.openId) userInfo.openId = wxContext.OPENID
if (!userInfo.unionId) userInfo.unionId = wxContext.UNIONID
let options = {
method: 'POST',
uri: 'https://xxx.xxx.xxx/api/',
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
form: userInfo,
json: true
}
let res = await rq(options).then(async body => {
console.log(body)
if (body.code == 200) {
userInfo.nickName = body.result.nickname
userInfo.avatarUrl = body.result.avatar
userInfo.uid = body.result.uid
userInfo.loginTime = db.serverDate()
await db.collection(collection).doc(userInfo.uid).set({
data: userInfo
})
}
return body
}).catch(err => {
return err
})
return res
}
是在 return 返回后的异步流程里调用的?
函数的日志截图看看
exports.main = async(event, context) => {
const wxContext = cloud.getWXContext()
const db = cloud.database()
const collection = 'user'
let userInfo = event.userInfo.data
console.log(event)
if (!userInfo.openId) userInfo.openId = wxContext.OPENID
if (!userInfo.unionId) userInfo.unionId = wxContext.UNIONID
let options = {
method: 'POST',
uri: 'https://xxx.xxx.xxx/api/',
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
form: userInfo,
json: true
}
let res = await rq(options).then(body => {
console.log(body)
if (body.code == 200) {
userInfo.nickName = body.result.nickname
userInfo.avatarUrl = body.result.avatar
userInfo.uid = body.result.uid
userInfo.loginTime = db.serverDate()
db.collection(collection).doc(userInfo.uid).set({
data: userInfo
}).then(e => {
console.log(e)
}).catch(er => {
console.log('云函数保存用户信息出错:', er)
})
}
return body
}).catch(err => {
return err
})
return res
}