[問題] firebase 的 error handle
各位大大好,最近在試用 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
→
02/22 11:44,
6年前
, 1F
02/22 11:44, 1F
→
02/22 11:45,
6年前
, 2F
02/22 11:45, 2F
→
02/22 11:46,
6年前
, 3F
02/22 11:46, 3F
謝謝大大!!在 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
→
03/06 04:41,
6年前
, 4F
03/06 04:41, 4F