forked from MapComplete/MapComplete
Move json data injection to approppriate place, fixes tests
This commit is contained in:
parent
a78d33112b
commit
c34f558c67
1 changed files with 13 additions and 9 deletions
16
Utils.ts
16
Utils.ts
|
@ -296,12 +296,6 @@ export class Utils {
|
|||
}
|
||||
|
||||
public static download(url: string, headers?: any): Promise<string> {
|
||||
const injected = Utils.injectedDownloads[url]
|
||||
if (injected !== undefined) {
|
||||
console.log("Using injected resource for test for URL", url)
|
||||
return new Promise((resolve, _) => resolve(injected))
|
||||
}
|
||||
|
||||
if (this.externalDownloadFunction !== undefined) {
|
||||
return this.externalDownloadFunction(url, headers)
|
||||
}
|
||||
|
@ -331,8 +325,18 @@ export class Utils {
|
|||
}
|
||||
|
||||
public static async downloadJson(url: string, headers?: any): Promise<any> {
|
||||
const injected = Utils.injectedDownloads[url]
|
||||
if (injected !== undefined) {
|
||||
console.log("Using injected resource for test for URL", url)
|
||||
return new Promise((resolve, _) => resolve(injected))
|
||||
}
|
||||
const data = await Utils.download(url, Utils.Merge({"accept": "application/json"}, headers ?? {}))
|
||||
try {
|
||||
return JSON.parse(data)
|
||||
} catch (e) {
|
||||
console.error("Could not parse ", data, "due to", e, "\n", e.stack)
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue