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

随声附和 提交于 2020-01-16 16:26:02

问题


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. What would be the correct way to send the error message through?


回答1:


Since the err.message is returning Internal, then you need to change the returned error to what you want:

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


来源:https://stackoverflow.com/questions/59334202/is-this-the-correct-way-of-returning-a-es6-promise-in-firebase-cloud-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!