【问题标题】:Firebase Messaging Error in Functions函数中的 Firebase 消息传递错误
【发布时间】:2018-05-17 19:42:36
【问题描述】:

在我的项目中,我使用 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 有什么变化吗?

【问题讨论】:

  • 请更新您的帖子以显示您如何处理send() 返回的 Promise 以及您是否发现错误。您看到的消息可能是令牌不再有效时返回的消息(例如,应用程序已卸载)。请参阅此相关帖子:stackoverflow.com/q/48928972/4815718
  • 我试图强制再次获取令牌,但我有同样的错误。
  • @BobSnyder,实际上这是来自 catch 的确切错误

标签: firebase firebase-cloud-messaging google-cloud-functions


【解决方案1】:

此错误表示您尝试发送通知的令牌不存在。

您必须在 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
    }
  }

【讨论】:

    猜你喜欢
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多