接口错误提示优化

This commit is contained in:
GaoHao
2025-01-13 14:18:43 +08:00
parent 97509d86d4
commit caa216fef0

View File

@@ -41,7 +41,7 @@ function commonsProcess(showLoading, httpReqCallback,isreturm) {
return httpReqCallback()
.then((httpData) => {
console.log(1)
reqFinishFunc(); // 请求完毕的动作
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
let { statusCode, data } = httpData;
@@ -95,15 +95,15 @@ function commonsProcess(showLoading, httpReqCallback,isreturm) {
return Promise.resolve(bodyData.data || bodyData.page|| bodyData);
})
.catch((res) => {
console.log(2)
if (res.status == 404) {
infoBox.showErrorToast("接口404").then(() => {});
infoBox.showToast("接口404").then(() => {});
reject();
return;
}
if (res.code == 401) {
infoBox.showErrorToast(res.message || "请登录").then(() => {
infoBox.showToast(res.message || "请登录").then(() => {
uni.redirectTo({
url: "/pages/login/login",
});
@@ -111,18 +111,18 @@ function commonsProcess(showLoading, httpReqCallback,isreturm) {
});
}
if (res.code != 0) {
infoBox.showErrorToast(res.msg).then(() => {});
infoBox.showToast(res.msg).then(() => {});
reject();
}
if (res.code == 500) {
infoBox.showErrorToast(res.msg || "服务器异常").then(() => {});
infoBox.showToast(res.msg || "服务器异常").then(() => {});
reject();
}
reqFinishFunc(); // 请求完毕的动作
// 如果没有提示错误, 那么此处提示 异常。
if (!isShowErrorToast) {
infoBox.showErrorToast(`请求网络异常`);
infoBox.showToast(`请求网络异常`);
}
return Promise.reject(res);
@@ -224,7 +224,7 @@ function upload(uri, data, file, showLoading = true, extParams = {}) {
})
.catch((err) => {
uni.hideLoading();
infoBox.showErrorToast(`上传失败`);
infoBox.showToast(`上传失败`);
});
});
}