Skip to content

Commit

Permalink
为ajax请求的返回错误进行分类报错 (hhyo#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
weideguo committed Jan 27, 2022
1 parent 3418432 commit ad861f7
Show file tree
Hide file tree
Showing 25 changed files with 45 additions and 105 deletions.
7 changes: 7 additions & 0 deletions common/static/dist/js/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var onLoadErrorCallback = function (status, jqXHR) {
if (status === 403) {
alert("权限错误,您没有权限查看该数据!");
} else {
alert("未知错误,数据加载失败!请检查接口返回信息和错误日志!");
}
};
1 change: 1 addition & 0 deletions common/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
<script src="{% static 'bootstrap-table/js/bootstrap-table-zh-CN.min.js' %}"></script>
<script src="{% static 'sql-formatter/sql-formatter.min.js' %}"></script>
<script src="{% static 'dist/js/formatter.js' %}"></script>
<script src="{% static 'dist/js/utils.js' %}"></script>

</body>
<script>
Expand Down
10 changes: 3 additions & 7 deletions sql/templates/archive.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html" %}
a{% extends "base.html" %}

{% block content %}
<!-- 自定义操作按钮-->
Expand Down Expand Up @@ -373,9 +373,7 @@ <h4 class="modal-title text-danger">工单日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down Expand Up @@ -629,9 +627,7 @@ <h4 class="modal-title text-danger">工单日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/archivedetail.html
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,7 @@ <h4><b>归档条件</b></h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
}

Expand Down
4 changes: 1 addition & 3 deletions sql/templates/audit.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/audit_sqlquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
8 changes: 2 additions & 6 deletions sql/templates/audit_sqlworkflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ <h4 class="modal-title text-danger">工单日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down Expand Up @@ -318,9 +316,7 @@ <h4 class="modal-title text-danger">工单日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/binlog2sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,7 @@ <h5 class="control-label text-bold" style="color: red">
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
} else {
alert(data.msg);
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/database.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ <h4 class="modal-title">编辑/录入数据库信息</h4>

}
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
16 changes: 4 additions & 12 deletions sql/templates/dbdiagnostic.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
alert("数据加载失败!" + data.msg);
}
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down Expand Up @@ -292,9 +290,7 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
alert("数据加载失败!" + data.msg);
}
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down Expand Up @@ -430,9 +426,7 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
alert("数据加载失败!" + data.msg);
}
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down Expand Up @@ -538,9 +532,7 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
alert("数据加载失败!" + data.msg);
}
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
12 changes: 3 additions & 9 deletions sql/templates/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,7 @@ <h4 class="modal-title text-danger">修改可执行时间</h4>
},
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
}

Expand Down Expand Up @@ -734,9 +732,7 @@ <h4 class="modal-title text-danger">修改可执行时间</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
Expand Down Expand Up @@ -839,9 +835,7 @@ <h4 class="modal-title text-danger">修改可执行时间</h4>
$("#osc-toolbar").show();
$('#osc_percent').modal('show');
},
onLoadError: function () {
alert("数据加载失败请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});

}
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/group.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: fonLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/groupmgmt.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ <h4 class="modal-title" id="myModalLabel">新增关联对象</h4>
],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/instance.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ <h4 class="modal-title" id="myModalLabel">清理Binlog日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/instanceaccount.html
Original file line number Diff line number Diff line change
Expand Up @@ -1152,9 +1152,7 @@ <h4 class="modal-title">删除账号

}
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/my2sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,7 @@ <h5 class="control-label text-bold" style="color: red">
onLoadSuccess: function () {

},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
} else {
alert(data.msg);
Expand Down
8 changes: 2 additions & 6 deletions sql/templates/param.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
return {
Expand Down Expand Up @@ -236,9 +234,7 @@
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
return {
Expand Down
8 changes: 2 additions & 6 deletions sql/templates/queryapplylist.html
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ <h4 class="modal-title text-danger">工单日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down Expand Up @@ -648,9 +646,7 @@ <h4 class="modal-title text-danger">工单日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/queryuserprivileges.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ <h4 class="modal-title text-danger">提示信息</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/rollback.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@
sessionStorage.setItem('editSqlContent', backup_sql);
}
},
onLoadError: function () {
alert("数据加载失败请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback,
});
$(document).ready(function () {
var isRollback = window.location.pathname.indexOf("rollback");
Expand Down
8 changes: 2 additions & 6 deletions sql/templates/slowquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@
sortable:true
}],
locale: 'zh-CN',
onLoadError: function() {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function(e) {
//传搜索参数给服务器
//console.info('search='+e);
Expand Down Expand Up @@ -576,9 +574,7 @@
singleSelect: true,
toolbar: "#sqladvisor-toolbar", //指明自定义的toolbar
locale: 'zh-CN',
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
8 changes: 3 additions & 5 deletions sql/templates/sqlanalyze.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ <h4 class="modal-title text-danger">分析报告</h4>
$('#sql-upload').fileinput('enable');
sessionStorage.setItem('analyze_text', text);
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
responseHandler: function (res) {
//在ajax获取到数据渲染表格之前修改数据源
return res;
Expand Down Expand Up @@ -345,10 +343,10 @@ <h4 class="modal-title text-danger">分析报告</h4>
$('#btn-analyze').removeClass('disabled');
$('#btn-analyze').prop('disabled', false);
},
onLoadError: function () {
onLoadError: function (status, jqXHR) {
$('#btn-analyze').removeClass('disabled');
$('#btn-analyze').prop('disabled', false);
alert("数据加载失败请检查接口返回信息和错误日志!");
onLoadErrorCallback(status, jqXHR);
},
responseHandler: function (res) {
//在ajax获取到数据渲染表格之前修改数据源
Expand Down
4 changes: 1 addition & 3 deletions sql/templates/sqlquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,7 @@ <h4 class="modal-title text-danger">收藏语句</h4>
re_query(query_log_id)
}
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down
8 changes: 2 additions & 6 deletions sql/templates/sqlworkflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ <h4 class="modal-title text-danger">工单日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
},
onLoadError: onLoadErrorCallback,
onSearch: function (e) {
//传搜索参数给服务器
queryParams(e)
Expand Down Expand Up @@ -325,9 +323,7 @@ <h4 class="modal-title text-danger">工单日志</h4>
}],
onLoadSuccess: function () {
},
onLoadError: function () {
alert("数据加载失败!请检查接口返回信息和错误日志!");
}
onLoadError: onLoadErrorCallback
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
Expand Down
Loading

0 comments on commit ad861f7

Please sign in to comment.