in my project I use Firebase Functions to send message via FCM. I use this API:
admin.messaging().send()
Recently and not for all token that I use to invoke it, I got this error:
Error: Requested entity was not found.
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16)
at Function.FirebaseMessagingError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:271:16)
at /user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:140:50
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
How can I solve it ?
I'm sure some time ago it works and these errors are not.
Any changes in Firebase?
This error means the token you are trying to send the notification, doesn't exists.
You must add your send code on a try catch block, and, depending on the error, erase (or invalidate) the token on your base.
try {
...
sendYourNotification(token);
...
} catch (error) {
if (
[
'The registration token is not a valid FCM registration token',
'Requested entity was not found.',
'NotRegistered.'
].includes(error.message)
) {
// invalidate current token
// find the user and remove this token
} else {
// Log it, because is some really unexpected
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With