I\'m developing Server with Firebase.
I had copied Google Developer\'s Video on Youtube.
It works well, but on log there is an error:
Adding to what @bob-snyder said, your problem is that your returning undefined under a condition.
if (post.sanitized) return;
My suggestion is to use a single exit point, which is a common tip when programming. Article.
// code...
const SUCCESS_CODE = 0;
exports.sanitizePost = functions.database
.ref('/posts/{pushId}')
.onWrite(event => {
const post = event.data.val();
let response = Promise.resolve(SUCCESS_CODE);
if (!post.sanitized) {
console.log('Sanitizing new post', event.params.pushId);
console.log(post);
post.sanitized = true;
post.title = sanitize(post.title);
post.body = sanitize(post.body);
response = event.data.ref.set(post);
}
return response;
})