梳理调用 response.error 时指定 code 的逻辑并补充文档
jysperm opened this issue · comments
Wang Ziting commented
因为 JS SDK 取消了 AV.Error:
AV.Error() is deprecated, and will be removed in next release.
很多用户会疑惑应该如何在 response.error 时指定 code,目前的替代方案是(注意是 message 而不是 error):
response.error({"code":"4444","message":"请先登录!"})
可能需要改进一下这个 API(例如将 code 作为第二个参数)并补充到文档上。
Lee Yeh commented
Accept an Error with message and code?
Wang Ziting commented
不过内建的 Error 并不能很方便地在构造函数里设置 code
Lee Yeh commented
恩,其实 AV.Error 就是这样一个内建 Error 的构造 helper,后来觉得这一层包装有点多余(而且还开放给用户了)就去掉了。
如果用户发现这里不方便,用户可以自己去做抽象。接收一个 Error 的好处是可以直接在错误处理链上将 response.error 作为异常处理方法使用:promise.catch(response.error)
。
Wang Ziting commented
这样说是没问题的,然后现有的格式也可以继续保留(response.error({"code":"4444","message":"请先登录!"})
),但这里的 message 和结果里的 error 字段很容易混淆。
Wang Ziting commented
#90
传一个 AV.Cloud.Error 即可。