4

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"?
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Markus Appel
  • 3,138
  • 1
  • 17
  • 46

1 Answers1

3

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.

Hiranya Jayathilaka
  • 7,180
  • 1
  • 23
  • 34