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

[ 功能建议 ]为ajax请求的返回错误进行分类报错 #1346

Closed
weideguo opened this issue Jan 18, 2022 · 3 comments
Closed

[ 功能建议 ]为ajax请求的返回错误进行分类报错 #1346

weideguo opened this issue Jan 18, 2022 · 3 comments

Comments

@weideguo
Copy link
Collaborator

目前遇到的问题/使用障碍

ajax请求后端时有一定概率因为权限出现报错,但现在的报错信息会让人困惑
before

希望如何解决/实现它

根据返回状态码,按照分类给出更详细的报错
after

即把原来的所有的函数

onLoadError: function () {
    alert("数据加载失败!请检查接口返回信息和错误日志!");
} 

替换成

onLoadError: function (status, jqXHR) {
    if (status === 403) {
        alert("权限错误,您没有权限查看该数据!");
    } else {
        alert("未知错误,数据加载失败!请检查接口返回信息和错误日志!");
    }
}
@LeoQuote
Copy link
Collaborator

jq 写的就是不好复用, 不如包装一个公用的请求函数, 然后到处都引用这个

@weideguo
Copy link
Collaborator Author

weideguo commented Jan 18, 2022

在创建文件sql/static/js/utils.js存放公共函数? @LeoQuote

@LeoQuote
Copy link
Collaborator

可以, 然后在 base 里 include 吧

weideguo added a commit to weideguo/Archery that referenced this issue Jan 27, 2022
hhyo pushed a commit that referenced this issue Jan 28, 2022
* 为ajax请求的返回错误进行分类报错 (#1346)

* 小优化
weideguo added a commit to weideguo/Archery that referenced this issue Jan 28, 2022
weideguo added a commit to weideguo/Archery that referenced this issue Jan 28, 2022
* 为ajax请求的返回错误进行分类报错 (hhyo#1346)

* 小优化
@hhyo hhyo closed this as completed Feb 12, 2022
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

3 participants