1

Firebaseにリアルタイムデータベーストリガを使用するクラウド関数を作成しています。それはonWriteを発生させ、次に私はPromisesを使って一連のコマンドを実行する必要があります。Firebase関数が必要です。プロンプトまたは値

私は1つの約束を使用するとコードを実行し、約束を連鎖させると信頼できなくなります。しかし、私は常にログにこれを取得する:必要な場所

Function returned undefined, expected Promise or value

私は値を返すいますし、まだ私は、このメッセージになってしまいました。私のコードは以下の通りです:

exports.sendQuotationToCustomer = functions.database.ref('/company/{companyId}/quotations/{quotationId}').onWrite((event) => { 
    const companyId = event.params.companyId; 
    console.log('Direct Generate'); 
    const root = event.data.ref.root; 
    return root.child(`company/${companyId}/profile`).once('value') 
    .then((profileSnap) => { 
    console.log('1/Step'); 
    const profile = profileSnap.val(); 
    const docDefinition = helpers.createDocumentDefinition(profile, quotationData); 
    return docDefinition; 
    }) 
    .then((result) => { 
    console.log('2/Step'); 
    // Perform some manipulation over result. But meanwhile: 
    return result; 
    }) 
    .catch((err) => { 
    console.log(`Failed with error info: ${err}`); 
    }); 
}); 

ここで間違っていますか?

+0

正確に 'docDefinition'とは何ですか? –

+0

こんにちは@DougStevenson、docDefinitionは私がステップ2で使用する予定のpdf生成用です。私はここにサンプルコードを書いています: 'https:// pastebin.com/Ubf10xqK' –

+0

また、約束を繋ぐときに「信頼できなくなる」と言われたらどういう意味ですか?手順2で非同期作業を行っていますか? –

答えて

0

私はあなたが警告を避けるためにキャッチして、エラーを返す必要があることを疑う:

.catch((err) => { 
    console.log(`Failed with error info: ${err}`); 
    return err; 
}); 

docDefinitionundefinedた場合、これがまた起こる可能性があります。これをチェックして、その場合はエラーを投げることをお勧めします。

関連する問題