Handle SENDER_ID_MISMATCH with a dedicated exception - #1126
Merged
Conversation
…ception FCM rejects messages sent to a registration token that belongs to a different Firebase project with 403 PERMISSION_DENIED and the error code SENDER_ID_MISMATCH. Until now, this response was converted to the same AuthenticationError as 401 responses, although the two conditions require opposite handling: a 401 is a service-level credential problem, while a sender ID mismatch is a permanent, per-token failure that should be handled like an unregistered token. MessagingApiExceptionConverter now converts 403 responses carrying the SENDER_ID_MISMATCH error code (or the "SenderId mismatch" message) to a new SenderIdMismatch exception. All other 401/403 responses are still converted to AuthenticationError. This mirrors the official Admin SDKs, which expose this condition as messaging/sender-id-mismatch (Node.js), MessagingErrorCode.SENDER_ID_MISMATCH (Java), and IsSenderIDMismatch() (Go).
Codecov Report✅ All modified and coverable lines are covered by tests.
@@ Coverage Diff @@
## 8.x #1126 +/- ##
=============================================
- Coverage 87.78% 40.91% -46.87%
- Complexity 1489 1497 +8
=============================================
Files 146 147 +1
Lines 4183 4184 +1
=============================================
- Hits 3672 1712 -1960
- Misses 511 2472 +1961 |
Member
|
Thanks for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1123
What this does
FCM rejects messages sent to a registration token that belongs to a different Firebase project with
403 PERMISSION_DENIEDand the error codeSENDER_ID_MISMATCH. Until now,MessagingApiExceptionConverter::convertResponse()converted this response to the sameAuthenticationErroras401responses, although the two conditions require opposite handling: a 401 is a service-level credential problem (alert an operator), while a sender ID mismatch is a permanent, per-token failure that should be handled like an unregistered token (prune the token, no alert).With this change, 403 responses carrying the
SENDER_ID_MISMATCHerror code in the error details (with the"SenderId mismatch"message as a fallback marker) are converted to a new, dedicatedKreait\Firebase\Exception\Messaging\SenderIdMismatchexception:This mirrors the official Admin SDKs (
messaging/sender-id-mismatchin Node.js,MessagingErrorCode.SENDER_ID_MISMATCHin Java,IsSenderIDMismatch()in Go) and follows the existing precedent ofNotFoundforUNREGISTEREDtokens.Backward compatibility
All other 401/403 responses are still converted to
AuthenticationError; only the specificSENDER_ID_MISMATCHcase gets the new type. The new exception implementsMessagingExceptionlike every other messaging exception, so genericcatch (MessagingException $e)handlers are unaffected.Included
SenderIdMismatchexception (same shape as the existingAuthenticationError/NotFound)MessagingApiExceptionConverter(error details first, message as fallback)AuthenticationError)docs/cloud-messaging.rst+ error-handling example updateChecks
test:unit: 361 tests OKanalyze(PHPStan): no errorslint(PHP-CS-Fixer + Rector): clean