I am wondering how to write node.js code correctly when I received the promises chain, and I need to update the database in real time if something goes wrong?
Here is the code:
export const testErrorHandling = functions.database
.ref('/workqueue/{pushId}/something').onWrite(event => {
if (!event.data.exists()) {
return;
}
const data = event.data.val()
if (data.count >= 5) {
return
}
return event.data.ref.root.child(data.fulluri).once('value').then(snapshot => {
return event.data.ref.remove()
}).catch(exception => {
console.log('Error!: ' + exception)
})
})
I would suggest that this is a common requirement in many cases, but cannot find an example, since all the examples seem to just be written to console.error and executed. (What rarely happens in the real world.)
source
share