Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

梳理调用 response.error 时指定 code 的逻辑并补充文档 #96

Closed
jysperm opened this issue Nov 4, 2016 · 5 comments
Closed

Comments

@jysperm
Copy link
Contributor

jysperm commented Nov 4, 2016

因为 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 作为第二个参数)并补充到文档上。

@leeyeh
Copy link
Contributor

leeyeh commented Feb 7, 2017

Accept an Error with message and code?

@jysperm
Copy link
Contributor Author

jysperm commented Feb 7, 2017

不过内建的 Error 并不能很方便地在构造函数里设置 code

@leeyeh
Copy link
Contributor

leeyeh commented Feb 7, 2017

恩,其实 AV.Error 就是这样一个内建 Error 的构造 helper,后来觉得这一层包装有点多余(而且还开放给用户了)就去掉了。

如果用户发现这里不方便,用户可以自己去做抽象。接收一个 Error 的好处是可以直接在错误处理链上将 response.error 作为异常处理方法使用:promise.catch(response.error)

@jysperm
Copy link
Contributor Author

jysperm commented Feb 7, 2017

这样说是没问题的,然后现有的格式也可以继续保留(response.error({"code":"4444","message":"请先登录!"})),但这里的 message 和结果里的 error 字段很容易混淆。

@jysperm
Copy link
Contributor Author

jysperm commented Mar 17, 2017

#90
传一个 AV.Cloud.Error 即可。

@jysperm jysperm closed this as completed Mar 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants