簡體   English   中英

函數中的 Firebase 消息傳遞錯誤

[英]Firebase Messaging Error in 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_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
    }
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM