这个提交包含在:
徐勤民 2024-10-18 20:30:27 +08:00
父节点 87ef142944
当前提交 2081e3d6fa

查看文件

@ -41,8 +41,8 @@ export class HttpHelper {
constructor() {
this.httpHandlerList = new HashMap<string, http.HttpRequest>();
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
this.concurrentList.clear()
}
@ -73,18 +73,19 @@ export class HttpHelper {
return new Promise<T>((resolve, reject) => {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 &&
this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.get(apiNo ?? params.url).destroy()
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
let httpRequest = http.createHttp();
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
const header = {
@ -104,7 +105,7 @@ export class HttpHelper {
extraData: params.data
})
.then((data: http.HttpResponse) => {
console.info('=====>' + 'Result:' + data.result as string);
console.info(`=====>Result:${data.result as string}(${apiNo})`);
// console.info('=====>' + 'code:' + data.responseCode);
// console.info('=====>' + 'type:' + JSON.stringify(data.resultType));
// console.info('=====>' + 'header:' + JSON.stringify(data.header));
@ -114,8 +115,8 @@ export class HttpHelper {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
if (data.responseCode === 200) {
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
@ -126,15 +127,17 @@ export class HttpHelper {
reject(err)
}
}).catch((err: Error) => {
console.info('=====>' + 'Error:' + JSON.stringify({ err: err, url: params.url, }));
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
if (err.message === 'Failed writing received data to disk/application') {
reject('cancel')
} else
} else {
reject(err)
}
});
});
@ -151,18 +154,19 @@ export class HttpHelper {
return new Promise<T>((resolve, reject) => {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 &&
this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.get(apiNo ?? params.url).destroy()
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
let httpRequest = http.createHttp();
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
const header = {
@ -184,7 +188,7 @@ export class HttpHelper {
extraData: encodeURI(data)
})
.then((data: http.HttpResponse) => {
console.info('=====>' + 'Result:' + data.result as string);
console.info(`=====>Result:${data.result as string}(${apiNo})`);
// console.info('=====>' + 'code:' + data.responseCode);
// console.info('=====>' + 'type:' + JSON.stringify(data.resultType));
// console.info('=====>' + 'header:' + JSON.stringify(data.header));
@ -194,8 +198,8 @@ export class HttpHelper {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
if (data.responseCode === 200) {
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
@ -206,15 +210,17 @@ export class HttpHelper {
reject(err)
}
}).catch((err: Error) => {
console.info('=====>' + 'Error:' + JSON.stringify({ err: err, url: params.url, }));
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
if (err.message === 'Failed writing received data to disk/application') {
reject('cancel')
} else
} else {
reject(err)
}
});
});
@ -233,18 +239,19 @@ export class HttpHelper {
return new Promise<T>((resolve, reject) => {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 && this.httpHandlerList.hasKey(apiNo ?? params.url)) {
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1 &&
this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.get(apiNo ?? params.url).destroy()
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
let httpRequest = http.createHttp();
if (this.concurrentList.getIndexOf(apiNo ?? params.url) === -1) {
this.httpHandlerList.set(apiNo ?? params.url, httpRequest)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
const header = {
@ -261,7 +268,7 @@ export class HttpHelper {
// extraData: params.data
})
.then((data: http.HttpResponse) => {
// console.info('=====>' + 'Result:' + data.result as string);
console.info(`=====>Result:${data.result as string}(${apiNo})`);
// console.info('=====>' + 'code:' + data.responseCode);
// console.info('=====>' + 'type:' + JSON.stringify(data.resultType));
// console.info('=====>' + 'header:' + JSON.stringify(data.header));
@ -271,8 +278,8 @@ export class HttpHelper {
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
if (data.responseCode === 200) {
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
@ -283,15 +290,17 @@ export class HttpHelper {
reject(err)
}
}).catch((err: Error) => {
console.info('=====>' + 'Error:' + JSON.stringify({ err: err, url: params.url, }));
if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
this.httpHandlerList.remove(apiNo ?? params.url)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList,this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength,this.httpHandlerList.length)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerList, this.httpHandlerList)
LocalStorageHelper.storage.setOrCreate(LocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
}
if (err.message === 'Failed writing received data to disk/application') {
reject('cancel')
} else
} else {
reject(err)
}
});
});