feat: 优化网络错误的提示文案,新增systemErrorHandler可用于自行处理系统错误

This commit is contained in:
ivinwu
2023-04-19 11:38:15 +08:00
parent dbb74eab66
commit 71fa0bdd9d
3 changed files with 8 additions and 2 deletions

View File

@@ -54,6 +54,8 @@ export interface IInitOption {
errorHandler?: Function | null;
/* 请求发送前提供hook给开发者自定义修改发送内容 */
beforeSend?: Function | null;
/* 自定义系统错误处理函数 */
systemErrorHandler?: Function | null;
}
export interface ICodeToSessionOptions{

View File

@@ -5,9 +5,11 @@ import { IRequestOption, IUploadFileOption } from "../interface";
function systemError(obj: IRequestOption | IUploadFileOption, res: WechatMiniprogram.GeneralCallbackResult) {
if (typeof obj.fail === "function") {
obj.fail(res);
} else if (typeof config.systemErrorHandler === 'function') {
config.systemErrorHandler(res);
} else {
const retry = () => request(obj).then(obj._resolve).catch(obj._reject);
doError("", res.errMsg, retry);
doError("", "", retry);
}
}

View File

@@ -30,7 +30,9 @@ const defaultConfig: IInitOption = {
// 自定义错误处理函数
errorHandler: null,
// 请求发送前提供hook给开发者自定义修改发送内容
beforeSend: null
beforeSend: null,
// 自定义系统错误处理函数(网络错误)
systemErrorHandler: null,
};
export default defaultConfig;