作者archon (内湖流川枫)
看板Python
标题[问题] firebase 的 error handle
时间Thu Feb 22 11:05:12 2018
各位大大好,最近在试用 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://webptt.com/cn.aspx?n=bbs/Python/M.1519268720.A.88B.html
※ 编辑: archon (220.136.17.186), 02/22/2018 11:29:09
2F:→ WunoW: 在看errorcode去分,但也没列出errorcode 02/22 11:45
3F:→ 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