@@ -44,15 +44,6 @@ def __init__(self, description):
44
44
DELETE_ATTRIBUTE = Sentinel ('Value used to delete an attribute from a user profile' )
45
45
46
46
47
- class ApiCallError (Exception ):
48
- """Represents an Exception encountered while invoking the Firebase user management API."""
49
-
50
- def __init__ (self , code , message , error = None ):
51
- Exception .__init__ (self , message )
52
- self .code = code
53
- self .detail = error
54
-
55
-
56
47
class UserMetadata (object ):
57
48
"""Contains additional metadata associated with a user account."""
58
49
@@ -510,7 +501,7 @@ def list_users(self, page_token=None, max_results=MAX_LIST_USERS_RESULTS):
510
501
try :
511
502
return self ._client .body ('get' , '/accounts:batchGet' , params = payload )
512
503
except requests .exceptions .RequestException as error :
513
- self . _handle_http_error ( USER_DOWNLOAD_ERROR , 'Failed to download user accounts.' , error )
504
+ raise _auth_utils . handle_auth_backend_error ( error )
514
505
515
506
def create_user (self , uid = None , display_name = None , email = None , phone_number = None ,
516
507
photo_url = None , password = None , disabled = None , email_verified = None ):
@@ -619,13 +610,15 @@ def import_users(self, users, hash_alg=None):
619
610
raise ValueError ('A UserImportHash is required to import users with passwords.' )
620
611
payload .update (hash_alg .to_dict ())
621
612
try :
622
- response = self ._client .body ('post' , '/accounts:batchCreate' , json = payload )
613
+ body , http_resp = self ._client .body_and_response (
614
+ 'post' , '/accounts:batchCreate' , json = payload )
623
615
except requests .exceptions .RequestException as error :
624
- self . _handle_http_error ( USER_IMPORT_ERROR , 'Failed to import users.' , error )
616
+ raise _auth_utils . handle_auth_backend_error ( error )
625
617
else :
626
- if not isinstance (response , dict ):
627
- raise ApiCallError (USER_IMPORT_ERROR , 'Failed to import users.' )
628
- return response
618
+ if not isinstance (body , dict ):
619
+ raise _auth_utils .UnexpectedResponseError (
620
+ 'Failed to import users.' , http_response = http_resp )
621
+ return body
629
622
630
623
def generate_email_action_link (self , action_type , email , action_code_settings = None ):
631
624
"""Fetches the email action links for types
@@ -640,7 +633,7 @@ def generate_email_action_link(self, action_type, email, action_code_settings=No
640
633
link_url: action url to be emailed to the user
641
634
642
635
Raises:
643
- ApiCallError : If an error occurs while generating the link
636
+ FirebaseError : If an error occurs while generating the link
644
637
ValueError: If the provided arguments are invalid
645
638
"""
646
639
payload = {
@@ -663,13 +656,6 @@ def generate_email_action_link(self, action_type, email, action_code_settings=No
663
656
'Failed to generate email action link.' , http_response = http_resp )
664
657
return body .get ('oobLink' )
665
658
666
- def _handle_http_error (self , code , msg , error ):
667
- if error .response is not None :
668
- msg += '\n Server response: {0}' .format (error .response .content .decode ())
669
- else :
670
- msg += '\n Reason: {0}' .format (error )
671
- raise ApiCallError (code , msg , error )
672
-
673
659
674
660
class _UserIterator (object ):
675
661
"""An iterator that allows iterating over user accounts, one at a time.
0 commit comments