|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import { login } from "../logic";
|
|
|
import { request as _request } from "../wx/network";
|
|
import { request as _request } from "../wx/network";
|
|
|
|
|
|
|
|
const shareRequestCache = new Map<string, IRequestData<any>>();
|
|
const shareRequestCache = new Map<string, IRequestData<any>>();
|
|
@@ -5,7 +6,7 @@ const shareRequestCache = new Map<string, IRequestData<any>>();
|
|
|
export function createRequest(option: IRequestCreateConfig) {
|
|
export function createRequest(option: IRequestCreateConfig) {
|
|
|
const { baseURL } = option;
|
|
const { baseURL } = option;
|
|
|
|
|
|
|
|
- return async <R, T>(config: IRequestConfig<R, T>) => {
|
|
|
|
|
|
|
+ return async function request<R, T>(config: IRequestConfig<R, T>) {
|
|
|
let { url, data, params, header, meta, transform = (params: any) => params, shareRequest, ..._config } = config;
|
|
let { url, data, params, header, meta, transform = (params: any) => params, shareRequest, ..._config } = config;
|
|
|
|
|
|
|
|
if (config.method === 'GET') {
|
|
if (config.method === 'GET') {
|
|
@@ -43,6 +44,20 @@ export function createRequest(option: IRequestCreateConfig) {
|
|
|
|
|
|
|
|
if (shareRequest) shareRequestCache.set(key, <any>promise);
|
|
if (shareRequest) shareRequestCache.set(key, <any>promise);
|
|
|
|
|
|
|
|
- return promise;
|
|
|
|
|
|
|
+ return (promise as any).catch(async (error: { errno: string }) => {
|
|
|
|
|
+ shareRequestCache.delete(key);
|
|
|
|
|
+ if (error.errno === '060201401') {
|
|
|
|
|
+ await login(true, '重新登录中');
|
|
|
|
|
+ wx.showLoading({ title: '重新加载中', });
|
|
|
|
|
+ try {
|
|
|
|
|
+ return await request(config);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ throw error;
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ wx.hideLoading();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ throw error;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|