首页 > 解决方案 > Cloud Functions .onCall() 无法返回数据

问题描述

我已经合并了三个 Observable pipe(),然后我将它转换为 Promise,以便我可以返回它。我已经用它测试了这个电话,onRequest()它工作得很好。但是,随着onCall()我不断收到此错误:

错误域 = NSCocoaErrorDomain 代码 = 3840 “JSON 文本没有以数组或对象开头,并且允许未设置片段的选项。” UserInfo={NSDebugDescription=JSON 文本没有以数组或对象开头,并且允许未设置片段的选项。}

我已经尝试了很多东西,但它们都返回相同的错误。我在这里做错了吗?

export const getNotifications = functions.region('europe-west1').https.onCall((data, context) => {

    const notificationsObs = rxjs.from(db.collection('notifications').where('receiverID', '==', 'jmwJLofoKpaQ4jligJKPc24UEe72').get());
    const requestObs = (requestsRef: any) => rxjs.from(db.getAll(...requestsRef));
    const packageObs = (packagesRef: any) => rxjs.from(db.getAll(...packagesRef));

    const notifications: Notification[] = [];
     return notificationsObs.pipe(
        mergeMap(snapshot => {
            //
            return requestObs(requestsRef);
        }),
        mergeMap((requests) => { // kthen requests
            //
            return packageObs(packagesRef)
        })
    ).toPromise().then(() => {
        return { notifications: "test" };
    }).catch(err => {err})
});

迅速

functions.httpsCallable("getNotifications").call() { (result, error) in
    if let error = error as NSError? {
        print(error)
    }

    print(result?.data) // nil
}

标签: javascriptnode.jsfirebaserxjsgoogle-cloud-functions

解决方案


所以不知何故onCall()不支持europe-west1。我删除了该区域,它工作正常。


推荐阅读