I've got a Google Apps Script:
function MakeHTTPCall() {
let resp = UrlFetchApp.fetch('https://something.cloudfunctions.net/returnStatusText');
console.log('Response code: ' + JSON.stringify(resp.getResponseCode()));
console.log('Returned text: ' + JSON.stringify(resp.getContentText()));
return;
}
And a Google Cloud Function (node.js 8)
exports.returnStatusText = async(req, res) => {
// Return codes
const ERR_OK = 200;
const ERR_STATUS_NO_CONTENT = 204;
// Get the email address sent
if ('undefined' === typeof req.body.emailAddress) {
// email address is undefined
console.log('No email address');
return res.status(ERR_STATUS_NO_CONTENT).send('DOH!');
}
return res.status(ERR_OK).send('OK');
}
My main reference is https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
What I expect is that the Google Cloud Function will log 'No email address' and the Google App Script will log 204 and 'DOH!'. What I get however is that the Google Cloud Function logs 'No email address' as expected, but the Google Apps Script logs 204 and the empty string. If I change ERR_STATUS_NO_CONTENT to 200, then the Google Apps Script log has 200 and 'DOH!' as expected. Is this a bug or am I missing something? I'm betting I'm missing something.