Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of invalid registration token? #805

Open
goncalossilva opened this issue Aug 26, 2024 · 2 comments
Open

Better handling of invalid registration token? #805

goncalossilva opened this issue Aug 26, 2024 · 2 comments

Comments

@goncalossilva
Copy link

goncalossilva commented Aug 26, 2024

[READ] Step 1: Are you in the right place?

Looks like it.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Any
  • Firebase SDK version: v6.5.0
  • Firebase Product: FCM
  • Python version: 3.11.9
  • Pip version: Any

[REQUIRED] Step 3: Describe the problem

This looks similar to #187, but that's been closed for years, so the similarity might no longer apply.

The crux of the issue is that not all scenarios of invalid registration IDs in FCM are supported equally. Particularly, there is the case of InvalidArgumentError due to an invalid registration ID which forces us to inspect the underlying HTTPError.

In other words, for us to handle all (known) scenarios where we should drop a particular registration ID, we currently have to:

    try:
        messaging.send(message)
    except (
        messaging.SenderIdMismatchError,
        messaging.UnregisteredError,
        messaging.ThirdPartyAuthError,
    ):
        # Handle errors that require dropping the registration ID
        # This is reasonably ergonomic!
        pass
    except exceptions.InvalidArgumentError as e:
        if e.http_response and "Invalid registration token" in e.http_response.text:
            # Handle errors that require dropping the registration ID
            # This is NOT ergonomic! Plus it relies on API internals not abstracted away by `firebase-admin-sdk`.
            pass

Is there any chance for first-party support of this error? Perhaps by re-raising as messaging.InvalidRegistrationIdError?

@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@goncalossilva @google-oss-bot and others