Skip to content

Commit 069c9cd

Browse files
authored
Handling FCM Canonical Errors (#218)
* Handling FCM Canonical Errors * Updated changelog
1 parent ec08be2 commit 069c9cd

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- [changed] Modified the Realtime Database client integration to report the
88
correct user agent header.
99
- [changed] Upgraded Cloud Firestire client to v0.12.0.
10+
- [changed] Improved error handling in FCM by mapping more server-side errors
11+
to client-side error codes.
1012

1113
# v5.9.0
1214

src/utils/error.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,20 @@ const MESSAGING_SERVER_TO_CLIENT_CODE: ServerToClientCode = {
613613
// Invalid APNs credentials.
614614
InvalidApnsCredential: 'INVALID_APNS_CREDENTIALS',
615615

616-
/* FCM new server API error codes */
617-
UNREGISTERED: 'REGISTRATION_TOKEN_NOT_REGISTERED',
616+
/* FCM v1 canonical error codes */
617+
NOT_FOUND: 'REGISTRATION_TOKEN_NOT_REGISTERED',
618+
PERMISSION_DENIED: 'MISMATCHED_CREDENTIAL',
619+
RESOURCE_EXHAUSTED: 'MESSAGE_RATE_EXCEEDED',
620+
UNAUTHENTICATED: 'INVALID_APNS_CREDENTIALS',
621+
622+
/* FCM v1 new error codes */
623+
APNS_AUTH_ERROR: 'INVALID_APNS_CREDENTIALS',
624+
INTERNAL: 'INTERNAL_ERROR',
618625
INVALID_ARGUMENT: 'INVALID_ARGUMENT',
619626
QUOTA_EXCEEDED: 'MESSAGE_RATE_EXCEEDED',
620627
SENDER_ID_MISMATCH: 'MISMATCHED_CREDENTIAL',
621-
APNS_AUTH_ERROR: 'INVALID_APNS_CREDENTIALS',
622628
UNAVAILABLE: 'SERVER_UNAVAILABLE',
623-
INTERNAL: 'INTERNAL_ERROR',
629+
UNREGISTERED: 'REGISTRATION_TOKEN_NOT_REGISTERED',
624630
UNSPECIFIED_ERROR: 'UNKNOWN_ERROR',
625631
};
626632

test/unit/messaging/messaging.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,20 @@ describe('Messaging', () => {
419419
.and.have.property('code', 'messaging/invalid-argument');
420420
});
421421

422+
it('should map server error code to client-side error', () => {
423+
const resp = {
424+
error: {
425+
status: 'NOT_FOUND',
426+
message: 'test error message',
427+
},
428+
};
429+
mockedRequests.push(mockSendError(404, 'json', resp));
430+
return messaging.send(
431+
{token: 'mock-token'},
432+
).should.eventually.be.rejectedWith('test error message')
433+
.and.have.property('code', 'messaging/registration-token-not-registered');
434+
});
435+
422436
it('should fail when the backend server returns an unknown error', () => {
423437
const resp = {error: 'test error message'};
424438
mockedRequests.push(mockSendError(400, 'json', resp));

0 commit comments

Comments
 (0)