File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,18 @@ export class FirebaseMessagingRequestHandler {
43
43
*/
44
44
private static getErrorCode ( response : any ) : string | null {
45
45
if ( validator . isNonNullObject ( response ) && 'error' in response ) {
46
- if ( typeof response . error === 'string' ) {
46
+ if ( validator . isString ( response . error ) ) {
47
47
return response . error ;
48
- } else if ( 'status' in response . error ) {
48
+ }
49
+ if ( validator . isArray ( response . error . details ) ) {
50
+ const fcmErrorType = 'type.googleapis.com/google.firebase.fcm.v1.FcmErrorCode' ;
51
+ for ( const element of response . error . details ) {
52
+ if ( element [ '@type' ] === fcmErrorType ) {
53
+ return element . errorCode ;
54
+ }
55
+ }
56
+ }
57
+ if ( 'status' in response . error ) {
49
58
return response . error . status ;
50
59
} else {
51
60
return response . error . message ;
Original file line number Diff line number Diff line change @@ -419,6 +419,26 @@ describe('Messaging', () => {
419
419
. and . have . property ( 'code' , 'messaging/invalid-argument' ) ;
420
420
} ) ;
421
421
422
+ it ( 'should fail when the backend server returns a detailed error with FCM error code' , ( ) => {
423
+ const resp = {
424
+ error : {
425
+ status : 'INVALID_ARGUMENT' ,
426
+ message : 'test error message' ,
427
+ details : [
428
+ {
429
+ '@type' : 'type.googleapis.com/google.firebase.fcm.v1.FcmErrorCode' ,
430
+ 'errorCode' : 'UNREGISTERED' ,
431
+ } ,
432
+ ] ,
433
+ } ,
434
+ } ;
435
+ mockedRequests . push ( mockSendError ( 404 , 'json' , resp ) ) ;
436
+ return messaging . send (
437
+ { token : 'mock-token' } ,
438
+ ) . should . eventually . be . rejectedWith ( 'test error message' )
439
+ . and . have . property ( 'code' , 'messaging/registration-token-not-registered' ) ;
440
+ } ) ;
441
+
422
442
it ( 'should map server error code to client-side error' , ( ) => {
423
443
const resp = {
424
444
error : {
You can’t perform that action at this time.
0 commit comments