函数中出现Firebase消息传递错误

函数中出现Firebase消息传递错误,firebase,firebase-cloud-messaging,google-cloud-functions,Firebase,Firebase Cloud Messaging,Google Cloud Functions,在我的项目中,我使用Firebase函数通过FCM发送消息。 我使用这个API: admin.messaging().send() 最近,并不是我用来调用它的所有令牌都出现了以下错误: Error: Requested entity was not found. at FirebaseMessagingError.Error (native) at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_mo

在我的项目中,我使用Firebase函数通过FCM发送消息。 我使用这个API:

admin.messaging().send()
最近,并不是我用来调用它的所有令牌都出现了以下错误:

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)
我怎样才能解决它? 我相信不久前它还可以工作,但这些错误并不存在。

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
    }
  }

请更新您的帖子,说明您如何处理
send()
返回的承诺,以及您是否发现了错误。您看到的消息可能是令牌不再有效时返回的消息(例如,应用程序已卸载)。请参阅此相关帖子:我试图强制再次获取令牌,但我有相同的错误。@BobSnyder,实际上这正是catch的错误