Skip to content

Commit 6efc63d

Browse files
authored
Handling THIRD_PARTY_AUTH_ERROR error code from FCM (#678)
1 parent 943e40c commit 6efc63d

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/utils/error.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ export class MessagingClientErrorCode {
710710
code: 'message-rate-exceeded',
711711
message: 'Sending limit exceeded for the message target.',
712712
};
713-
public static INVALID_APNS_CREDENTIALS = {
714-
code: 'invalid-apns-credentials',
713+
public static THIRD_PARTY_AUTH_ERROR = {
714+
code: 'third-party-auth-error',
715715
message: 'A message targeted to an iOS device could not be sent because the required APNs ' +
716716
'SSL certificate was not uploaded or has expired. Check the validity of your development ' +
717717
'and production certificates.',
@@ -904,20 +904,21 @@ const MESSAGING_SERVER_TO_CLIENT_CODE: ServerToClientCode = {
904904
// Topics message rate exceeded.
905905
TopicsMessageRateExceeded: 'TOPICS_MESSAGE_RATE_EXCEEDED',
906906
// Invalid APNs credentials.
907-
InvalidApnsCredential: 'INVALID_APNS_CREDENTIALS',
907+
InvalidApnsCredential: 'THIRD_PARTY_AUTH_ERROR',
908908

909909
/* FCM v1 canonical error codes */
910910
NOT_FOUND: 'REGISTRATION_TOKEN_NOT_REGISTERED',
911911
PERMISSION_DENIED: 'MISMATCHED_CREDENTIAL',
912912
RESOURCE_EXHAUSTED: 'MESSAGE_RATE_EXCEEDED',
913-
UNAUTHENTICATED: 'INVALID_APNS_CREDENTIALS',
913+
UNAUTHENTICATED: 'THIRD_PARTY_AUTH_ERROR',
914914

915915
/* FCM v1 new error codes */
916-
APNS_AUTH_ERROR: 'INVALID_APNS_CREDENTIALS',
916+
APNS_AUTH_ERROR: 'THIRD_PARTY_AUTH_ERROR',
917917
INTERNAL: 'INTERNAL_ERROR',
918918
INVALID_ARGUMENT: 'INVALID_ARGUMENT',
919919
QUOTA_EXCEEDED: 'MESSAGE_RATE_EXCEEDED',
920920
SENDER_ID_MISMATCH: 'MISMATCHED_CREDENTIAL',
921+
THIRD_PARTY_AUTH_ERROR: 'THIRD_PARTY_AUTH_ERROR',
921922
UNAVAILABLE: 'SERVER_UNAVAILABLE',
922923
UNREGISTERED: 'REGISTRATION_TOKEN_NOT_REGISTERED',
923924
UNSPECIFIED_ERROR: 'UNKNOWN_ERROR',

test/unit/messaging/messaging.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,28 @@ describe('Messaging', () => {
504504
.and.have.property('code', 'messaging/registration-token-not-registered');
505505
});
506506

507+
['THIRD_PARTY_AUTH_ERROR', 'APNS_AUTH_ERROR'].forEach((errorCode) => {
508+
it(`should map ${errorCode} to third party auth error`, () => {
509+
const resp = {
510+
error: {
511+
status: 'INVALID_ARGUMENT',
512+
message: 'test error message',
513+
details: [
514+
{
515+
'@type': 'type.googleapis.com/google.firebase.fcm.v1.FcmError',
516+
'errorCode': errorCode,
517+
},
518+
],
519+
},
520+
};
521+
mockedRequests.push(mockSendError(404, 'json', resp));
522+
return messaging.send(
523+
{token: 'mock-token'},
524+
).should.eventually.be.rejectedWith('test error message')
525+
.and.have.property('code', 'messaging/third-party-auth-error');
526+
});
527+
});
528+
507529
it('should map server error code to client-side error', () => {
508530
const resp = {
509531
error: {

0 commit comments

Comments
 (0)