forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
e33d448055
commit
d2134668b1
25 changed files with 109 additions and 171 deletions
25
src/Utils.ts
25
src/Utils.ts
|
@ -879,7 +879,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
): Promise<
|
||||
| { content: string }
|
||||
| { redirect: string }
|
||||
| { error: string; url: string; statuscode?: number, errContent?: string }
|
||||
| { error: string; url: string; statuscode?: number; errContent?: string }
|
||||
> {
|
||||
let result = undefined
|
||||
for (let i = 0; i < maxAttempts; i++) {
|
||||
|
@ -917,7 +917,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
): Promise<
|
||||
| { content: string }
|
||||
| { redirect: string }
|
||||
| { error: string; url: string; statuscode?: number, errContent: string }
|
||||
| { error: string; url: string; statuscode?: number; errContent: string }
|
||||
> {
|
||||
if (this.externalDownloadFunction !== undefined) {
|
||||
return this.externalDownloadFunction(url, headers)
|
||||
|
@ -931,13 +931,18 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
} else if (xhr.status === 302) {
|
||||
resolve({ redirect: xhr.getResponseHeader("location") })
|
||||
} else if (xhr.status === 509 || xhr.status === 429) {
|
||||
resolve({ error: "rate limited", url, statuscode: xhr.status, errContent: xhr.responseText })
|
||||
resolve({
|
||||
error: "rate limited",
|
||||
url,
|
||||
statuscode: xhr.status,
|
||||
errContent: xhr.responseText,
|
||||
})
|
||||
} else {
|
||||
resolve({
|
||||
error: "other error: " + xhr.statusText + ", " + xhr.responseText,
|
||||
url,
|
||||
statuscode: xhr.status,
|
||||
errContent: xhr.responseText
|
||||
errContent: xhr.responseText,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1013,7 +1018,9 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
headers?: Record<string, string>,
|
||||
dontCacheErrors = false,
|
||||
maxAttempts = 3
|
||||
): Promise<{ content: T } | { error: string; url: string; statuscode?: number, errContent?: object }> {
|
||||
): Promise<
|
||||
{ content: T } | { error: string; url: string; statuscode?: number; errContent?: object }
|
||||
> {
|
||||
const cached = Utils._download_cache.get(url)
|
||||
if (cached !== undefined) {
|
||||
if (new Date().getTime() - cached.timestamp <= maxCacheTimeMs) {
|
||||
|
@ -1023,8 +1030,8 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
const promise =
|
||||
/*NO AWAIT as we work with the promise directly */ Utils.downloadJsonAdvanced<T>(
|
||||
url,
|
||||
headers,
|
||||
maxAttempts
|
||||
headers,
|
||||
maxAttempts
|
||||
)
|
||||
Utils._download_cache.set(url, { promise, timestamp: new Date().getTime() })
|
||||
try {
|
||||
|
@ -1065,7 +1072,9 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
|||
url: string,
|
||||
headers?: Record<string, string>,
|
||||
maxAttempts = 3
|
||||
): Promise<{ content: T } | { error: string; url: string; statuscode?: number, errContent?: object }> {
|
||||
): Promise<
|
||||
{ content: T } | { error: string; url: string; statuscode?: number; errContent?: object }
|
||||
> {
|
||||
const injected = Utils.injectedDownloads[url]
|
||||
if (injected !== undefined) {
|
||||
return { content: injected }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue