Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- [changed] Modified the Realtime Database client integration to report the
correct user agent header.
- [changed] Upgraded Cloud Firestire client to v0.12.0.
- [changed] Improved error handling in FCM by mapping more server-side errors
to client-side error codes.

# v5.9.0

Expand Down
14 changes: 10 additions & 4 deletions src/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,20 @@ const MESSAGING_SERVER_TO_CLIENT_CODE: ServerToClientCode = {
// Invalid APNs credentials.
InvalidApnsCredential: 'INVALID_APNS_CREDENTIALS',

/* FCM new server API error codes */
UNREGISTERED: 'REGISTRATION_TOKEN_NOT_REGISTERED',
/* FCM v1 canonical error codes */
NOT_FOUND: 'REGISTRATION_TOKEN_NOT_REGISTERED',
PERMISSION_DENIED: 'MISMATCHED_CREDENTIAL',
RESOURCE_EXHAUSTED: 'MESSAGE_RATE_EXCEEDED',
UNAUTHENTICATED: 'INVALID_APNS_CREDENTIALS',

/* FCM v1 new error codes */
APNS_AUTH_ERROR: 'INVALID_APNS_CREDENTIALS',
INTERNAL: 'INTERNAL_ERROR',
INVALID_ARGUMENT: 'INVALID_ARGUMENT',
QUOTA_EXCEEDED: 'MESSAGE_RATE_EXCEEDED',
SENDER_ID_MISMATCH: 'MISMATCHED_CREDENTIAL',
APNS_AUTH_ERROR: 'INVALID_APNS_CREDENTIALS',
UNAVAILABLE: 'SERVER_UNAVAILABLE',
INTERNAL: 'INTERNAL_ERROR',
UNREGISTERED: 'REGISTRATION_TOKEN_NOT_REGISTERED',
UNSPECIFIED_ERROR: 'UNKNOWN_ERROR',
};

Expand Down
14 changes: 14 additions & 0 deletions test/unit/messaging/messaging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,20 @@ describe('Messaging', () => {
.and.have.property('code', 'messaging/invalid-argument');
});

it('should map server error code to client-side error', () => {
const resp = {
error: {
status: 'NOT_FOUND',
message: 'test error message',
},
};
mockedRequests.push(mockSendError(404, 'json', resp));
return messaging.send(
{token: 'mock-token'},
).should.eventually.be.rejectedWith('test error message')
.and.have.property('code', 'messaging/registration-token-not-registered');
});

it('should fail when the backend server returns an unknown error', () => {
const resp = {error: 'test error message'};
mockedRequests.push(mockSendError(400, 'json', resp));
Expand Down