File tree 3 files changed +31
-3
lines changed
3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Unreleased
2
2
3
- -
3
+ - [ changed] Improved error handling in FCM by mapping more server-side
4
+ errors to client-side error codes.
4
5
5
6
# v2.9.0
6
7
Original file line number Diff line number Diff line change @@ -716,11 +716,18 @@ class _MessagingService(object):
716
716
INTERNAL_ERROR = 'internal-error'
717
717
UNKNOWN_ERROR = 'unknown-error'
718
718
FCM_ERROR_CODES = {
719
- 'APNS_AUTH_ERROR' : 'authentication-error' ,
719
+ # FCM v1 canonical error codes
720
+ 'NOT_FOUND' : 'registration-token-not-registered' ,
721
+ 'PERMISSION_DENIED' : 'mismatched-credential' ,
722
+ 'RESOURCE_EXHAUSTED' : 'message-rate-exceeded' ,
723
+ 'UNAUTHENTICATED' : 'invalid-apns-credentials' ,
724
+
725
+ # FCM v1 new error codes
726
+ 'APNS_AUTH_ERROR' : 'invalid-apns-credentials' ,
720
727
'INTERNAL' : INTERNAL_ERROR ,
721
728
'INVALID_ARGUMENT' : 'invalid-argument' ,
722
729
'QUOTA_EXCEEDED' : 'message-rate-exceeded' ,
723
- 'SENDER_ID_MISMATCH' : 'authentication-error ' ,
730
+ 'SENDER_ID_MISMATCH' : 'mismatched-credential ' ,
724
731
'UNAVAILABLE' : 'server-unavailable' ,
725
732
'UNREGISTERED' : 'registration-token-not-registered' ,
726
733
}
Original file line number Diff line number Diff line change @@ -855,6 +855,26 @@ def test_send_detailed_error(self, status):
855
855
body = {'message' : messaging ._MessagingService .JSON_ENCODER .default (msg )}
856
856
assert json .loads (recorder [0 ].body .decode ()) == body
857
857
858
+ @pytest .mark .parametrize ('status' , HTTP_ERRORS )
859
+ def test_send_canonical_error_code (self , status ):
860
+ payload = json .dumps ({
861
+ 'error' : {
862
+ 'status' : 'NOT_FOUND' ,
863
+ 'message' : 'test error'
864
+ }
865
+ })
866
+ _ , recorder = self ._instrument_messaging_service (status = status , payload = payload )
867
+ msg = messaging .Message (topic = 'foo' )
868
+ with pytest .raises (messaging .ApiCallError ) as excinfo :
869
+ messaging .send (msg )
870
+ assert str (excinfo .value ) == 'test error'
871
+ assert str (excinfo .value .code ) == 'registration-token-not-registered'
872
+ assert len (recorder ) == 1
873
+ assert recorder [0 ].method == 'POST'
874
+ assert recorder [0 ].url == self ._get_url ('explicit-project-id' )
875
+ body = {'message' : messaging ._MessagingService .JSON_ENCODER .default (msg )}
876
+ assert json .loads (recorder [0 ].body .decode ()) == body
877
+
858
878
859
879
class TestTopicManagement (object ):
860
880
You can’t perform that action at this time.
0 commit comments