- 添加请求异常提示,和拦截

This commit is contained in:
sin 2019-04-11 21:28:32 +08:00
parent 70e21f9194
commit 1509bd26c7

View File

@ -114,7 +114,7 @@ const servicef = function (parameter) {
data = JSON.parse(data); data = JSON.parse(data);
} }
resolve(data); resolve(data);
}) });
return promist; return promist;
} }
// 设置 access token // 设置 access token
@ -128,7 +128,7 @@ const servicef = function (parameter) {
// debugger; // debugger;
return service(parameter); return service(parameter);
} };
service.interceptors.request.use( service.interceptors.request.use(
@ -160,7 +160,7 @@ service.interceptors.request.use(
console.log(error) // for debug console.log(error) // for debug
Promise.reject(error) Promise.reject(error)
} }
) );
// response interceptor // response interceptor
service.interceptors.response.use( service.interceptors.response.use(
@ -192,8 +192,6 @@ service.interceptors.response.use(
// }) // })
// } // }
// TODO token 过期 // TODO token 过期
// TODO 需要拿 refresh token 置换 // TODO 需要拿 refresh token 置换
if (code === 1001001012) { if (code === 1001001012) {
@ -218,7 +216,6 @@ service.interceptors.response.use(
message: res.message, message: res.message,
}); });
} }
console.log(1);
return Promise.reject('error') return Promise.reject('error')
} else { } else {
// if (typeof response.data.Tag == 'string') { // if (typeof response.data.Tag == 'string') {
@ -231,10 +228,15 @@ service.interceptors.response.use(
} }
}, },
error => { error => {
Dialog.alert({
return Promise.reject(error) title: '系统提示',
message: error,
});
console.error(`请求失败`, error);
throw new Error(error);
// return Promise.reject(error)
} }
) );
export default servicef export default servicef