什么错误代码对应于MessagingErrorCode的成员?

huangapple go评论103阅读模式
英文:

What error codes do members of MessagingErrorCode correspond to?

问题

关于从Firebase客户端版本6迁移到7的问题。

过去,我们在com.google.firebase.messaging.SendResponse实例上调用了.getException().getErrorCode()

我们特别处理了两种情况,即"registration-token-not-registered""mismatched-credential"

从版本7开始,有两种不同的错误代码可以检索,一种是通过.getException().getErrorCode()(返回通用的ErrorCode),另一种是通过.getException.getMessagingErrorCode()(返回更合适的MessagingErrorCode)。

版本7的迁移指南清楚地显示,"registration-token-not-registered"的第一种情况现在可以通过.getException.getMessagingErrorCode()来处理,并且可以与MessagingErrorCode.UNREGISTERED进行匹配,但是"mismatched-credential"(以及所有其他可能的错误)的情况没有在任何地方记录。

我能找到的最好的东西是枚举的文档

但我不确定

> 用于对此SDK进行身份验证的凭据没有权限向与提供的注册令牌对应的设备发送消息

(来自Admin错误代码文档)和

> 经过身份验证的发送者ID与注册令牌的发送者ID不同。

(来自枚举MessagingErrorCode.SENDER_ID_MISMATCH的文档)是否意味着相同的事情...


我的问题有两个方面:

  • 是否有一种很好的方式将MessagingErrorCode与实际的Admin错误代码关联起来?

  • MessagingErrorCode.SENDER_ID_MISMATCH是否是"mismatched-credential"的正确错误代码?

英文:

This is regarding a migration from Firebase client version 6 to 7.

In the past, we called .getException().getErrorCode() on an instance of com.google.firebase.messaging.SendResponse.

We handled two cases specifically, "registration-token-not-registered" and "mismatched-credential".

Since version 7, there are two different error codes that can be retrieved, one with .getException().getErrorCode() (returning an generic ErrorCode) and .getException.getMessagingErrorCode() (returning a more fitting MessagingErrorCode).

The migration guide to version 7 clearly shows that the first case of "registration-token-not-registered" can now be handled with .getException.getMessagingErrorCode() and matching against MessagingErrorCode.UNREGISTERED, but the case of "mismatched-credential" (and all other possible errors) isn't documented anywhere.

The best thing I could find is the documentation of the enum.

But I am not sure if

> The credential used to authenticate this SDK does not have permission to send messages to the device corresponding to the provided registration token

(from the Admin Error codes documentation) and

> The authenticated sender ID is different from the sender ID for the registration token.

(from the documentation of the enum MessagingErrorCode.SENDER_ID_MISMATCH) means the same...


My question is twofold:

  • Is there a nice way to relate MessagingErrorCodes to the actual Admin error codes?

  • Is the MessagingErrorCode.SENDER_ID_MISMATCH the right error code for "mismatched-credential"?

答案1

得分: 3

MessagingErrorCode 与旧版 Admin 错误代码关联

你正在引用的Admin 错误代码文档 仅适用于当前的 Node.js SDK,该 SDK 仍然采用旧的方式表示 API 错误。因此,如果你使用的是除了 Node.js 之外的编程语言(并且使用最新的 Firebase SDK),请忽略那些遗留的错误代码,只处理在提供的枚举中明确定义的错误代码。在许多情况下,这些旧错误代码与新错误代码之间并没有直接的一对一映射关系。

关于错误代码的最新信息,你应该参考Admin SDK 错误处理

mismatched-credential 错误代码

旧的 mismatched-credential 错误代码曾经表示两种不同的错误情况:

  1. 实际的令牌不匹配错误,调用者无权发送到给定的设备令牌。
  2. 其他一般权限错误,是因为授权凭证缺少所需的 IAM 角色/权限。

新的 v7 Java SDK 在这两种情况之间进行了区分。情况 1 由 MessagingErrorCode.SENDER_ID_MISMATCH 表示。

> SENDER_ID_MISMATCH - 身份验证的发送者 ID 与注册令牌的发送者 ID 不同。这通常意味着发送者和目标注册令牌不在同一个 Firebase 项目中。

情况 2 会导致 ErrorCode.PERMISSION_DENIED,没有 MessagingErrorCode 的值。

> PERMISSION_DENIED - 客户端权限不足。这可能是因为 OAuth 令牌没有正确的范围,客户端没有权限,或者 API 尚未对客户端项目启用。

大多数开发者只想在他们的代码中处理情况 1。情况 2 几乎总是配置错误。

英文:

Relating MessagingErrorCode to legacy Admin error codes

The Admin error code documentation you're referencing only applies to the Node.js SDK today, which is still stuck in the old way of representing API errors. So if you're coding in a language other than Node.js (and using the latest available Firebase SDKs), disregard those legacy error codes and just handle the ones that are explicitly defined in the provided enums. There's no direct 1:1 mapping between those legacy and new error codes in many cases.

For most up-to-date information regarding error codes you should refer to Admin SDK error handling.

The mismatched-credential error code

The old mismatched-credential error code used to represent two separate error conditions:

  1. Actual token mismatch errors where the caller is not authorized to send to the given device token.
  2. Other general permission errors due to the authorization credential lacking the required IAM roles/permissions.

The new v7 Java SDK differentiates between these two cases. Case 1 is represented by MessagingErrorCode.SENDER_ID_MISMATCH.

> SENDER_ID_MISMATCH The authenticated sender ID is different from the sender ID for the registration token. This usually means the sender and the target registration token are not in the same Firebase project.

Case 2 results in an ErrorCode.PERMISSION_DENIED with no MessagingErrorCode value.

> PERMISSION_DENIED Client does not have sufficient permission. This can happen because the OAuth token does not have the right scopes, the client does not have permission, or the API has not been enabled for the client project.

Most developers would only want to handle case 1 in their code. Case 2 is almost always a configuration error.

huangapple
  • 本文由 发表于 2020年9月22日 16:04:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/64005494.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定