I want to delete two entries: one in database (Firestore), the other in storage (Cloud Storage). The following code should fulfill this goal.
However, in the logs of Cloud Functions, these lines are shown:
> 1st line: Function execution started
> 2nd line: Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
> 3rd line: Function execution took 821 ms, finished with status code: 200
> 4th line: Unhandled rejection
> 5th line: Error: Unable to delete the image.
\n at /srv/index.js:59:9
\n at <anonymous>
\n at process._tickDomainCallback (internal/process/next_tick.js:229:7)
I think the error that is shown in line 2 causes the "errors" displayed in lines 4 and 5.
I have Spark Plan (the free billing account) and normally, all Google networks should be accessible. The image I'm trying to delete, and the database entry, are stored in Google servers! So I'm not using any "External network", thus my script actually should work (correct me if I'm mistaken).
I don't think I've done any error in my code.
Here it is:
const request2 = require('request');
const {Storage} = require('@google-cloud/storage');
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase)
const storage = new Storage();
const admin_firestore = admin.firestore();
exports.deletePost = functions.https.onCall((data, context) => {
if(!context.auth) {
throw new functions.https.HttpsError('failed-precondition', 'The function must be called while authenticated.');
}
const the_post = data.the_post;
const filePath = context.auth.uid + '/posts/' + the_post;
const promise_1 = storage.bucket('android-framrk-fxxx.appspot.com').file(filePath).delete();
promise_1.then(function() {
const promise_2 = admin_firestore.collection('users').document(context.auth.uid).collection('posts').document(the_post).delete();
return promise_2.then(function() {
return 1;
}).catch(function() {
throw new functions.https.HttpsError('unknown', 'Unable to delete the post.');
});
}).catch(function() {
throw new functions.https.HttpsError('unknown', 'Unable to delete the image.');
});
});
My question
Am I correct? i.e.: is it a bug from the Google devs team? Or did I make a mistake in my code that I didn't see?