|
@@ -29,7 +29,10 @@ export class HttpHelper {
|
|
|
this.httpHandlerList = new HashMap<string, http.HttpRequest>();
|
|
this.httpHandlerList = new HashMap<string, http.HttpRequest>();
|
|
|
SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
|
|
SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength, this.httpHandlerList.length)
|
|
|
- this.concurrentList.clear()
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ this.concurrentList.clear()
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -40,27 +43,39 @@ export class HttpHelper {
|
|
|
if (!apiNo) {
|
|
if (!apiNo) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- if (this.concurrentList.getIndexOf(apiNo) === -1) {
|
|
|
|
|
- this.concurrentList.add(apiNo)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.concurrentList.getIndexOf(apiNo) === -1) {
|
|
|
|
|
+ this.concurrentList.add(apiNo)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
public addConcurrents(apiNo: string[]) {
|
|
public addConcurrents(apiNo: string[]) {
|
|
|
for (let apiNoElement of apiNo) {
|
|
for (let apiNoElement of apiNo) {
|
|
|
- if (this.concurrentList.getIndexOf(apiNoElement) === -1) {
|
|
|
|
|
- this.concurrentList.add(apiNoElement)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.concurrentList.getIndexOf(apiNoElement) === -1) {
|
|
|
|
|
+ this.concurrentList.add(apiNoElement)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public removeConcurrent(apiNo: string) {
|
|
public removeConcurrent(apiNo: string) {
|
|
|
- if (this.concurrentList.getIndexOf(apiNo) !== -1) {
|
|
|
|
|
- this.concurrentList.remove(apiNo)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.concurrentList.getIndexOf(apiNo) !== -1) {
|
|
|
|
|
+ this.concurrentList.remove(apiNo)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
public removeConcurrents(apiNo: string[]) {
|
|
public removeConcurrents(apiNo: string[]) {
|
|
|
for (let apiNoElement of apiNo) {
|
|
for (let apiNoElement of apiNo) {
|
|
|
- if (this.concurrentList.getIndexOf(apiNoElement) !== -1) {
|
|
|
|
|
- this.concurrentList.remove(apiNoElement)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.concurrentList.getIndexOf(apiNoElement) !== -1) {
|
|
|
|
|
+ this.concurrentList.remove(apiNoElement)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -100,12 +115,6 @@ export class HttpHelper {
|
|
|
LogHelper.print(data)
|
|
LogHelper.print(data)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
- }
|
|
|
|
|
if (data.responseCode === 200) {
|
|
if (data.responseCode === 200) {
|
|
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
|
|
} else {
|
|
} else {
|
|
@@ -116,12 +125,6 @@ export class HttpHelper {
|
|
|
}
|
|
}
|
|
|
}).catch((err: Error) => {
|
|
}).catch((err: Error) => {
|
|
|
LogHelper.error(JSON.stringify({ err: err, url: params.url, }))
|
|
LogHelper.error(JSON.stringify({ err: err, url: params.url, }))
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
- }
|
|
|
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
|
const error: Error = new Error()
|
|
const error: Error = new Error()
|
|
|
error.name = 'cancel'
|
|
error.name = 'cancel'
|
|
@@ -130,26 +133,39 @@ export class HttpHelper {
|
|
|
} else {
|
|
} else {
|
|
|
reject(err)
|
|
reject(err)
|
|
|
}
|
|
}
|
|
|
|
|
+ }).finally(() => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
+ this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
+ this.httpHandlerList.length)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setHandler(key: string, httpRequest: http.HttpRequest) {
|
|
setHandler(key: string, httpRequest: http.HttpRequest) {
|
|
|
- if (this.concurrentList.getIndexOf(key) === -1 &&
|
|
|
|
|
- this.httpHandlerList.hasKey(key)) {
|
|
|
|
|
- this.httpHandlerList.get(key).destroy()
|
|
|
|
|
- this.httpHandlerList.remove(key)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.concurrentList.getIndexOf(key) === -1 &&
|
|
|
|
|
+ this.httpHandlerList.hasKey(key)) {
|
|
|
|
|
+ this.httpHandlerList.get(key).destroy()
|
|
|
|
|
+ this.httpHandlerList.remove(key)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
}
|
|
}
|
|
|
- if (this.concurrentList.getIndexOf(key) === -1) {
|
|
|
|
|
- this.httpHandlerList.set(key, httpRequest)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.concurrentList.getIndexOf(key) === -1) {
|
|
|
|
|
+ this.httpHandlerList.set(key, httpRequest)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
}
|
|
}
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
+ this.httpHandlerList.length)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -187,12 +203,6 @@ export class HttpHelper {
|
|
|
LogHelper.print(data)
|
|
LogHelper.print(data)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
- }
|
|
|
|
|
if (data.responseCode === 200) {
|
|
if (data.responseCode === 200) {
|
|
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
|
|
} else {
|
|
} else {
|
|
@@ -203,12 +213,6 @@ export class HttpHelper {
|
|
|
}
|
|
}
|
|
|
}).catch((err: Error) => {
|
|
}).catch((err: Error) => {
|
|
|
LogHelper.error(JSON.stringify({ err: err, url: params.url, }))
|
|
LogHelper.error(JSON.stringify({ err: err, url: params.url, }))
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
- }
|
|
|
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
|
const error: Error = new Error()
|
|
const error: Error = new Error()
|
|
|
error.name = 'cancel'
|
|
error.name = 'cancel'
|
|
@@ -217,6 +221,16 @@ export class HttpHelper {
|
|
|
} else {
|
|
} else {
|
|
|
reject(err)
|
|
reject(err)
|
|
|
}
|
|
}
|
|
|
|
|
+ }).finally(() => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
+ this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
+ this.httpHandlerList.length)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -257,12 +271,6 @@ export class HttpHelper {
|
|
|
LogHelper.print(data)
|
|
LogHelper.print(data)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
- }
|
|
|
|
|
if (data.responseCode === 200) {
|
|
if (data.responseCode === 200) {
|
|
|
|
|
|
|
|
if (typeof data.result === 'string') {
|
|
if (typeof data.result === 'string') {
|
|
@@ -278,12 +286,6 @@ export class HttpHelper {
|
|
|
}
|
|
}
|
|
|
}).catch((err: Error) => {
|
|
}).catch((err: Error) => {
|
|
|
LogHelper.error(JSON.stringify({ err: err, url: params.url, }))
|
|
LogHelper.error(JSON.stringify({ err: err, url: params.url, }))
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
- }
|
|
|
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
|
const error: Error = new Error()
|
|
const error: Error = new Error()
|
|
|
error.name = 'cancel'
|
|
error.name = 'cancel'
|
|
@@ -292,6 +294,16 @@ export class HttpHelper {
|
|
|
} else {
|
|
} else {
|
|
|
reject(err)
|
|
reject(err)
|
|
|
}
|
|
}
|
|
|
|
|
+ }).finally(() => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
+ this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
+ this.httpHandlerList.length)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -354,11 +366,14 @@ export class HttpHelper {
|
|
|
}
|
|
}
|
|
|
}).finally(() => {
|
|
}).finally(() => {
|
|
|
httpRequest.off("dataSendProgress");
|
|
httpRequest.off("dataSendProgress");
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
|
|
+ this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
+ this.httpHandlerList.length)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -373,12 +388,15 @@ export class HttpHelper {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
cancel(apiNo: string) {
|
|
cancel(apiNo: string) {
|
|
|
- if (this.httpHandlerList.hasKey(apiNo)) {
|
|
|
|
|
- this.httpHandlerList.get(apiNo).destroy()
|
|
|
|
|
- this.httpHandlerList.remove(apiNo)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
- this.httpHandlerList.length)
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (this.httpHandlerList.hasKey(apiNo)) {
|
|
|
|
|
+ this.httpHandlerList.get(apiNo).destroy()
|
|
|
|
|
+ this.httpHandlerList.remove(apiNo)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
|
|
+ this.httpHandlerList.length)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|