看板 Python 關於我們 聯絡資訊
各位大大好,最近在試用 firebase 的 SDK 遇到一個困難, 就是不知道要怎麼有效的 error handle 舉個例子來說,我想創一個帳號 --------------------------------------------------------------- import firebase_admin from firebase_admin import credentials, auth try: newUser = auth.create_user(email=email, password=password) except Exception as e: print(e) ---------------------------------------------------------------- 這時可能會有各式各樣的錯誤,像是 email 不合法、密碼不合法、 帳號已經有人用了 blah blah... 但 except type 這邊是 ValueError 這種,我很不好分析... 我是照著下面這則 firebase guides 的實作 https://firebase.google.com/docs/auth/admin/manage-users 裡頭只寫發生錯誤會 throws an error. For a full list of error codes, including descriptions and resolution steps, see Admin Auth API Errors. 但 API Error 表只列出了 error list,卻沒有獲得訊息的方式 https://firebase.google.com/docs/auth/admin/errors 如果能拿到 'auth/invalid-password' 這樣的 error code 那就會非常方便, 請問要怎麼樣能夠拿到呢... QwQ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.136.17.186 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1519268720.A.88B.html ※ 編輯: archon (220.136.17.186), 02/22/2018 11:29:09
WunoW: 官方文件python只有一個AuthError http://bit.ly/2EHWZh2 02/22 11:44
WunoW: 在看errorcode去分,但也沒列出errorcode 02/22 11:45
WunoW: 這文件就很一般的敷衍型的,開發人員要自己看原始碼 02/22 11:46
謝謝大大!!在 firebase_admin 的 auth.py 裡這麼寫著: def create_user(**kwargs): """ Raises: ValueError: If the specified user properties are invalid. AuthError: If an error occurs while creating the user account. """ app = kwargs.pop('app', None) user_manager = _get_auth_service(app).user_manager try: uid = user_manager.create_user(**kwargs) return UserRecord(user_manager.get_user(uid=uid)) except _user_mgt.ApiCallError as error: raise AuthError(error.code, str(error), error.detail) 這麼一看就有眉目了!!! ※ 編輯: archon (220.136.17.186), 02/22/2018 13:11:14
galeondx: https://tinyurl.com/yadsk3lo 03/06 04:41