Better handling of invalid registration token?

Open
#805 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api

Research direction

Start at the messaging.send path and inspect how InvalidArgumentError, SenderIdMismatchError, and UnregisteredError are currently raised. Trace the HTTP response handling for the “Invalid registration token” case and determine the public error behavior needed. Done means callers can handle this invalid-token scenario without inspecting HTTP internals, with coverage for the relevant error path.

Written by the indexing model from the issue text.

Description

api: messaging
[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?

Dominant language
Python
Stars
1.2k
Forks
359
Avg merge
5d 6m
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/firebase-admin-python

All issues in firebase/firebase-admin-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.