async _before() {
// 通用预处理器
const methodName = this.getMethodName()
if (!this.getUniIdToken()) {
throw new Error('token不存在')
}
// token信息
const token = this.getUniIdToken()
const clientInfo = this.getClientInfo()
const tokenRes = await uniID
.createInstance({
clientInfo,
})
.checkToken(token)
if (tokenRes.errCode && tokenRes.errMsg) {
// throw tokenRes
throw {
errCode: 'hehe',
errMsg: 'lala',
}
}
let uid
if (tokenRes.uid) {
uid = tokenRes.uid
}
this.uid = uid
}
_before预处理的代码中我使用throw抛出错误,但是前端收到的是{"code":"FUNCTION_EXCUTE_ERROR","message":"请求云函数出错"}
,这是为什么?
我如果不使用throw,使用return去返回,这样更不行,直接往下走了。
1 个回复
DCloud_uniCloud_WYQ
before内抛出的错误也可以在after内再加工进行return,参考uni-id-co的写法:uni-id-co