enf*_*fix 5 firebase google-cloud-functions firebase-cloud-messaging
在我的项目中,我使用 Firebase 函数通过 FCM 发送消息。我使用这个 API:
admin.messaging().send()
Run Code Online (Sandbox Code Playgroud)
最近而不是我用来调用它的所有令牌,我收到了这个错误:
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)
Run Code Online (Sandbox Code Playgroud)
我该如何解决?我确定前段时间它可以工作,而这些错误则无效。
Firebase 有什么变化吗?
此错误意味着您尝试发送通知的令牌不存在。
您必须在 try catch 块上添加发送代码,并根据错误擦除(或无效)基础上的令牌。
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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2462 次 |
| 最近记录: |