Firebase云功能 - 函数返回未定义,预期的Promise或value

时间:2018-01-02 12:47:57

标签: javascript firebase google-cloud-functions mailgun

我通过其他线程阅读并试图将某些内容返回给我的云函数,但它仍然提供相同的函数返回未定义,预期的Promise或值警告......我在这里缺少什么?

基本上,我发送了两封使用mailgun-js发送给用户和管理员的电子邮件,即使发送成功了,我仍然会在日志中收到相同的警告。

exports.sendSample = functions.database
.ref( 'sample/{pushID}' )
.onWrite( event => {

    //  only trigger if it's new
    if ( !event.data.exists() || event.data.previous.exists() ) return 0

    const e = event.data.val()

    const toUser = {
        to      : `${ e.email }`,
        from    : `xxx`,
        subject : `xxx`,
        html    : `xxx`
    }

    const toAdmin = {
        to      : `${ e.admin }`,
        from    : `xxx`,
        subject : `xxx`,
        html    : `xxx`
    }

    //  send sms
    if ( e.mobile !== 'none' ) {
        return client.messages.create({
            body : `xxx`,
            to   : `${e.mobile}`,
            from : `xxx`
        })
        .then( message => {
            sendEmail()
            return message.sid
        })
        .catch( err => {
            return err
        })
    } else {
        sendEmail()
    }

    //  send email
    function sendEmail() {
        if ( e.email !== 'none' ) {
            return mailgun.messages().send( toUser, ( err, body ) => {
                return ( err, body )
                return mailgun.messages().send( toAdmin, ( err, body ) => {
                    return ( err, body )
                })
            })
        } else {
            return true
        }
    }
})

2 个答案:

答案 0 :(得分:1)

如前所述,您需要返回一个值。

if (e.email !== 'none') {
    ...
} else {
    return true;
}

答案 1 :(得分:0)

这个怎么样?

Sub Chapters_Mcq()
    Application.ScreenUpdating = False
    Dim Sht3 As Worksheet
    Dim Sht2 As Worksheet
    Dim i As Long
    Set Sht3 = Worksheets("Chapters")
    Set Sht2 = Worksheets("Mcq Results")
    Sht3.Range("A2:A13").Copy
    Sht2.Cells(Rows.Count, 7).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    Sht3.Range("B2:B13").Copy
    Sht2.Cells(Rows.Count, 8).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    Sht3.Range("C2:C13").Copy
    Sht2.Cells(Rows.Count, 13).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

// send sms
if ( e.mobile !== 'none' ) {
  ...

} else {
    sendEmail()
}