request.js 优化
This commit is contained in:
parent
3902e20553
commit
f09e59c16c
|
|
@ -15,20 +15,9 @@ import {
|
||||||
|
|
||||||
// 环境配置
|
// 环境配置
|
||||||
const ENV_CONFIG = {
|
const ENV_CONFIG = {
|
||||||
develop: {
|
|
||||||
// 开发环境
|
|
||||||
baseUrl: "http://192.168.2.58:4502",
|
|
||||||
//baseUrl: "https://testlu.chuangtewl.com/prod-api",
|
|
||||||
appId: 1,
|
|
||||||
},
|
|
||||||
trial: {
|
|
||||||
// 体验版
|
|
||||||
baseUrl: "http://192.168.2.58:4502",
|
|
||||||
appId: 1,
|
|
||||||
},
|
|
||||||
release: {
|
release: {
|
||||||
// 正式版
|
// 正式版
|
||||||
baseUrl: "http://192.168.2.58:4502",
|
baseUrl: "http://192.168.2.100:4501",
|
||||||
appId: 1,
|
appId: 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -120,13 +109,11 @@ function handleResponseError(res, reject, options = {}) {
|
||||||
title: "请求的资源不存在",
|
title: "请求的资源不存在",
|
||||||
action: () => {},
|
action: () => {},
|
||||||
},
|
},
|
||||||
500: {
|
|
||||||
title: "服务器错误",
|
|
||||||
action: () => {},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const error = errorMap[res.statusCode] || {
|
console.log("response:", res);
|
||||||
|
|
||||||
|
const error = errorMap[res.data.code] || {
|
||||||
title: res.data?.msg || "请求失败",
|
title: res.data?.msg || "请求失败",
|
||||||
action: () => {},
|
action: () => {},
|
||||||
};
|
};
|
||||||
|
|
@ -194,7 +181,7 @@ export function request(options = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求成功处理
|
// 请求成功处理
|
||||||
if (res.statusCode === 200) {
|
if (res.code === 200 || res.data.code === 200) {
|
||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
} else {
|
} else {
|
||||||
// 处理错误响应
|
// 处理错误响应
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user