Firebase Cloud Function with Firestore returning “Deadline Exceeded”

后端 未结 5 1564
暗喜
暗喜 2020-12-09 09:28

I took one of the sample functions from the Firestore documentation and was able to successfully run it from my local firebase environment. However, once I deployed to my fi

5条回答
  •  既然无缘
    2020-12-09 10:02

    If the error is generate after around 10 seconds, probably it's not your internet connetion, it might be that your functions are not returning any promise. In my experience I got the error simply because I had wrapped a firebase set operation(which returns a promise) inside another promise. You can do this

    return db.collection("COL_NAME").doc("DOC_NAME").set(attribs).then(ref => {
            var SuccessResponse = {
                "code": "200"
            }
    
            var resp = JSON.stringify(SuccessResponse);
            return resp;
        }).catch(err => {
            console.log('Quiz Error OCCURED ', err);
            var FailureResponse = {
                "code": "400",
            }
    
            var resp = JSON.stringify(FailureResponse);
            return resp;
        });
    

    instead of

    return new Promise((resolve,reject)=>{ 
        db.collection("COL_NAME").doc("DOC_NAME").set(attribs).then(ref => {
            var SuccessResponse = {
                "code": "200"
            }
    
            var resp = JSON.stringify(SuccessResponse);
            return resp;
        }).catch(err => {
            console.log('Quiz Error OCCURED ', err);
            var FailureResponse = {
                "code": "400",
            }
    
            var resp = JSON.stringify(FailureResponse);
            return resp;
        });
    
    });
    

提交回复
热议问题