0

I try to make a Firebase Cloud Function that updates some references, according to the query values passed for the HTTP request.

Here's my function:

exports.saveBuy = functions.https.onRequest((req, res) => {

    const shopID = req.query.shopID;
    const userID = req.query.userID;

    const shopRef = db.collection('Shops').doc(shopID)
    const userRef = db.collection('Users').doc(userID)

    const increment = firebase.firestore.FieldValue.increment(1)

    var batch = db.batch();

    batch.update(shopRef, ({count: increment}));

    batch.update(shopRef, ({clients: firebase.firestore.FieldValue.arrayUnion(userId)}));

    batch.update(userRef, ({purchases: firebase.firestore.FieldValue.arrayUnion(shopId)}));

    // Commit the batch
    batch.commit().then(function () {
        console.log('success')
        res.status(200).send()
        return null
    }).catch(error => { res.status(500).send();
            return console.error(error)});

});

I make batch updates, and I want to return a 200 status in case of success. However, the Firebase Log shows me "Function execution took 868 ms, finished with status: 'crash'"...

Kolya
  • 99
  • 2
  • 10
  • Do you get an error from the `console.error`? or does it just say "crash" – DJ Burb Aug 22 '20 at 22:21
  • Just "crash" bro – Kolya Aug 22 '20 at 22:25
  • It looks like an issue on Google's end according to this post: https://stackoverflow.com/questions/61987350/is-finished-with-status-crash-normal-for-cloud-functions – DJ Burb Aug 22 '20 at 22:29
  • But how can I solve this problem? Do you know an other way?? – Kolya Aug 22 '20 at 22:45
  • Try returning `batch.commit()` – frunkad Aug 22 '20 at 22:56
  • @frunkad I need to return a status, because I will call this http function in my app – Kolya Aug 23 '20 at 07:55
  • Hi @Koyla as mentioned in previous comments, you should follow this public [thread](https://issuetracker.google.com/issues/155215191) for updates. Once this issue is fixed, you will be able to understand what it's causing the issue, including its status. – gso_gabriel Aug 24 '20 at 11:30

0 Answers0