firebase / firebase/firebase-admin-python

Better handling of invalid registration token?

Abierto
#805 1 comentario 0 reacciones 0 asignados Ver en GitHub
api: messaging
Lenguaje dominante
Python
Estrellas
1.2k
Forks
359
Merge medio
5 d 6 min
PR fusionados (30 d)
2

Descripción

### [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:

```python
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`?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.