我有一个可调用的Google Cloud Function,它在前端调用如下:
const register = this.$fireFunc.httpsCallable('registerForTournament');
register(this.$route.params.id)
.then(result => {
console.log(result);
this.$store.commit('tournaments/addRegistered', {
id: this.tournament.id,
user: { uid: this.user.uid, displayName: this.user.displayName }
});
this.loadingRegister = false;
})
.catch(error => {
console.log('no error???');
this.$toast.error(error);
this.loadingRegister = false;
});
现在该函数被调用并返回以下内容
data: { code: "cancelled", details: null }
但是,如果发生这种情况,函数应该触发错误吗? 这是一个有关如何在函数中引发错误的示例:
if (!userObject.displayName) {
throw new functions.https.HttpsError('cancelled', 'The Player has no display Name defined.');
}