Move json data injection to approppriate place, fixes tests

This commit is contained in:
pietervdvn 2021-09-28 18:40:45 +02:00
parent a78d33112b
commit c34f558c67

View file

@ -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;
}
}
/**