简体   繁体   English

Firebase云函数错误-函数返回未定义,预期的承诺或价值

[英]Firebase cloud functions error - Function returned undefined, expected Promise or value

I'm trying to log a purchase event on Appsflyer with a Google Cloud Function when a new document is created but I have this error. 创建新文档时,我正在尝试使用Google Cloud Function在Appsflyer上记录购买事件,但出现此错误。

All my interpolations seems to be good in my logs. 我的所有插值在我的日志中似乎都不错。 My function is 我的功能是

exports.validatePaymentAppsflyer = functions.firestore.document('_orderFinishedSuccessfully/{id}').onCreate((snap, context) => {

    console.log(snap, context);

    const newValue = snap.data();
    const requestData = newValue;
    console.log(requestData.platform);

    if ( requestData.platform === 'ios' ) {
        appId = 'id1303984176';                
    } else {
        appId = 'com.myapp';                
    }

    var request = require("request");

    var options = { method: 'POST',
    url: 'https://api2.appsflyer.com/inappevent/' + appId,
    headers: 
    { 
        "authentication": 'M762jn36Bb7kBt70jNdtrU',
        'Content-Type': 'application/json' 
        },
    body: 
    { appsflyer_id: requestData.appsflyerId,
        customer_user_id: requestData.customerUserId,
        eventName: 'af_purchase',
        eventValue: {
            "af_revenue":requestData.totalTTC,
            "af_order_id":requestData.orderId,
            "af_city":requestData.city,
            "af_date_b":requestData.date
        },
        eventCurrency: 'EUR',
        ip: requestData.userIp,
        eventTime: requestData.date,
        af_events_api: 'true' },
    json: true };

    console.log(options);


    request(options, function (error, response, body) {
    if (error) throw new Error(error);

    console.log(body);
    });
});

I need your help 我需要你的帮助

Cloud functions are expected to return something meaningful, most often you'd want to return a Promise . 期望云函数返回有意义的东西,大多数情况下,您通常希望返回Promise That way the engine will know that your async operations have finished and doesn't have to wait for a timeout to happen. 这样,引擎将知道您的异步操作已经完成,而不必等待超时发生。

To fix your code, just return a Promise : 要修复您的代码,只需返回Promise

return new Promise((resolve, reject) => {
    request(options, function (error, response, body) {
        if (error) reject(error);
        else resolve(response);
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase Cloud Functions“函数返回了未定义的,预期的承诺或价值” - Firebase Cloud Functions “Function returned undefined, expected Promise or value” Firebase云功能-返回的函数未定义,预期的承诺或价值 - Firebase cloud functions - Function returned undefined, expected Promise or value Firebase Cloud Function错误,未返回函数,预期的承诺或价值 - Firebase Cloud Function error, Function returned undefined, expected Promise or value Firebase云函数错误:函数返回的值未定义,预期的承诺或价值 - Firebase cloud function error: Function returned undefined, expected Promise or value Firebase云异步错误(函数返回未定义,预期的承诺或值) - Firebase Cloud Async Error(Function returned undefined, expected Promise or value) Firebase云功能计划:返回的函数未定义,预期的承诺或价值 - Firebase cloud function schedule: Function returned undefined, expected Promise or value Function 返回未定义,预期 Promise 或值,无法使用云功能从 firebase 数据库中删除旧数据 - Function returned undefined, expected Promise or value and unable to delete old data from firebase database using cloud functions Firebase云功能-返回未定义,期望的承诺或价值 - Firebase cloud function - returned undefined,expected Promise or value OneSignal 和 Firebase 云函数 - 返回未定义、预期的 Promise 或值 - OneSignal & Firebase Cloud Function - Returned undefined, expected Promise or value Function 返回未定义、预期 Promise 或 Cloud Functions 中的值 - Function returned undefined, expected Promise or value in Cloud Functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM