Files
weRequest/src/module/errorHandler.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-12-19 19:26:38 +08:00
import config from '../store/config'
2018-12-20 21:21:58 +08:00
export default (obj: TODO, res: TODO) => {
2018-12-19 19:26:38 +08:00
if (typeof obj.fail === "function") {
obj.fail(res);
} else {
let title = "";
if (typeof config.errorTitle === "function") {
try {
2018-12-20 21:21:58 +08:00
title = config.errorTitle(res.data || res.errMsg)
2018-12-19 19:26:38 +08:00
} catch (e) {
}
2018-12-20 21:21:58 +08:00
} else if (typeof config.errorTitle === "string") {
2018-12-19 19:26:38 +08:00
title = config.errorTitle;
}
let content = "";
if (typeof config.errorContent === "function") {
try {
2018-12-20 21:21:58 +08:00
content = config.errorContent(res.data || res.errMsg)
2018-12-19 19:26:38 +08:00
} catch (e) {
}
} else if (typeof config.errorContent === "string") {
content = config.errorContent;
}
wx.showModal({
title: title,
content: content || "网络或服务异常,请稍后重试",
showCancel: false
})
}
// 如果有配置统一错误回调函数,则执行它
if (typeof config.errorCallback === "function") {
config.errorCallback(obj, res);
}
console.error(res);
}