javascript – 在Firebase云功能上抛出新函数.https.HttpsError拒绝客户端上的内部错误
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 在Firebase云功能上抛出新函数.https.HttpsError拒绝客户端上的内部错误,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1787字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 在Firebase云功能上抛出新函数.https.HttpsError拒绝客户端上的内部错误](/upload/InfoBanner/zyjiaocheng/718/f60c3fb28c994527ba6cb903ccb393aa.jpg)
我在Firebase项目中部署了以下云功能:
exports.createCredentials = functions.https.onCall((data, context) => {
if(!context.auth)
throw new functions.https.HttpsError('failed-auth', 'You must be authenticated to call this function')
const { email, password } = data;
if(!(typeof email === 'string'))
throw new functions.https.HttpsError('invalid-email', 'Email must be a string')
if(!(typeof password === 'string'))
throw new functions.https.HttpsError('invalid-password', 'Password must be a string')
return admin.auth().createUser({
email,
password
})
.then(userRecord => {
return { userRecord }
})
.catch((error) => {
throw new functions.https.HttpsError(error.code, error.message)
})
})
问题是每当我抛出一个新的函数.https.HttpsError而不是在客户端捕获的错误作为docs状态时,我得到一个内部错误代码.在我的函数的日志中,它显示了一个未处理的错误,我尝试调用HttpsError.这是日志的一个例子:
Unhandled error Error: Unknown error status: auth/email-already-exists
at new HttpsError (/user_code/node_modules/firebase-functions/lib/providers/https.js:80:19)
at admin.auth.createUser.then.catch (/user_code/index.js:26:9)
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
我知道如果没有抛出HttpsError,这种类型的函数会拒绝内部错误,但据我所知,在我的函数中并非如此.我在React中编写我的前端,所以这就是我如何调用这个firebase函数:
let options = {
email: arquitect.email,
password: arquitect.password
}
let createCredentials = firebase.functions().httpsCallable('createCredentials')
createCredentials(options)
.then(result => {
})
.catch(error => console.log(error))
有什么我想念的吗?
解决方法:
根据您链接的文档,您似乎没有使用functions.https.HttpsError中列出的值作为代码参数.该值必须是Google API的规范错误代码之一.例如,“failed-auth”或“invalid-email”未列在那里.您可以改为使用“permission-denied”或“invalid-argument”.
内容总结
以上是互联网集市为您收集整理的javascript – 在Firebase云功能上抛出新函数.https.HttpsError拒绝客户端上的内部错误全部内容,希望文章能够帮你解决javascript – 在Firebase云功能上抛出新函数.https.HttpsError拒绝客户端上的内部错误所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。