简体   繁体   English

这是在 firebase 云函数中返回 ES6 承诺的正确方法吗?

[英]Is this the correct way of returning a ES6 promise in firebase cloud functions?

I have a cloud function similar to this:我有一个与此类似的云功能:

exports.verifyEmail = functions.https.onCall((data, context) => { // data contains session_id (doc id where otp is stored) and otp
  return new Promise((resolve, reject) => {
    admin.firestore().collection('verification').doc(data.session_id).get().then(doc => {
      if(data.otp === doc.data().otp){
        return resolve()
      } else {
        return reject({message: 'OTP did not match'})
      }
    }).catch(err => {
      return reject({message: err.message})
    })
  })
})

I read this method on a blog somewhere.我在某个地方的博客上读到了这种方法。 Now the problem is, when I put wrong OTP on the client side, it shows error as INTERNAL rather than showing the error message OTP did not match .现在的问题是,当我在客户端放置错误的 OTP 时,它将错误显示为INTERNAL而不是显示错误消息OTP did not match What would be the correct way to send the error message through?发送错误消息的正确方法是什么?

Since the err.message is returning Internal , then you need to change the returned error to what you want:由于err.message返回Internal ,那么您需要将返回的错误更改为您想要的:

}).catch(err => {
      return reject({message: "OTP did not match"})
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM