api 支持无status 字段返回

This commit is contained in:
liaoxuezhi 2020-12-07 22:38:52 +08:00
parent ded3240372
commit ade2d70bab

View File

@ -164,12 +164,14 @@ function str2function(
function responseAdaptor(ret: fetcherResult) {
const data = ret.data;
let hasStatusField = true;
if (!data) {
throw new Error('Response is empty!');
} else if (!data.hasOwnProperty('status')) {
// 兼容不返回 status 字段的情况
data.status = 0;
hasStatusField = false;
}
const payload: Payload = {
@ -177,7 +179,7 @@ function responseAdaptor(ret: fetcherResult) {
status: data.status,
msg: data.msg,
msgTimeout: data.msgTimeout,
data: !data.data && !data.hasOwnProperty('status') ? data : data.data // 兼容直接返回数据的情况
data: !data.data && !hasStatusField ? data : data.data // 兼容直接返回数据的情况
};
if (payload.status == 422) {