问题
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