I have a situation in firebase cloud function where only FIRST console.log or firestore update statement is executed.
I have other similar function with slight variation in the way response is processed, but that does not have any issues
I have checked google cloud console/firebase console etc and the source code seem to have been uploaded correctly
exports.myFunction = functions.firestore.document(docPath).onCreate(async (snapshot, context) => {
var inputData = snapshot.data();
console.log('printing request');
console.log(inputData);
//Prepare to call the api
var data = {'input': 'some value'};
var resource = 'api_resource';
// call api - below function is provided by an external provider and takes a callback function once api call is complete
myApi.call(resource, data.input, function (error, result) {
if (error) {
console.log('Error from api');
return { status: 'error', code: 401, message: 'Error from api' }
}
var apiResult = JSON.parse(result);
console.log('printing api response'); // <-- Anything below this does not get executed. When this is removed, next line is executed and so on
console.log(apiResult);
//Write to Firestore
snapshot.ref.update({
'status': 'computed',
})
.then((a) => {
console.log('Written successfully to db');
return 0;
})
.catch(err => {
console.log('Error setting db' + err);
return { status: 'error', code: 401, message: 'Error setting db ' }
});
// console.log('End of function');
return { status: 'success', code: 200, message: 'Completed successfully' }
});
});
I see another post that is opposite of this situation. Anyone know why this happens?