From 293e03be4626776126aba7a2a144f04e05328a5b Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 16 Dec 2022 01:00:43 +0100 Subject: [PATCH] Fix utils.ts --- Utils.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Utils.ts b/Utils.ts index 242df3ca89..1f27eb7203 100644 --- a/Utils.ts +++ b/Utils.ts @@ -802,30 +802,30 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be } public static async download(url: string, headers?: any): Promise { - return (await Utils.downloadAdvanced(url, headers))["content"] + const result = await Utils.downloadAdvanced(url, headers) + if(result["error"] !== undefined){ + throw result["error"] + } + return result["content"] } /** * Download function which also indicates advanced options, such as redirects * @param url * @param headers - * @param onStatusCode Callback which is always triggered with the status code */ public static downloadAdvanced( url: string, headers?: any, - onStatusCode?: (code:number) => void ): Promise<{ content: string } | { redirect: string } | { error: string,url: string, statuscode?: number}> { if (this.externalDownloadFunction !== undefined) { return this.externalDownloadFunction(url, headers) } + console.trace("Fetching XHR", url) return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest() xhr.onload = () => { - if(onStatusCode ){ - onStatusCode(xhr.status) - } if (xhr.status == 200) { resolve({ content: xhr.response }) } else if (xhr.status === 302) { @@ -922,13 +922,13 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be url, Utils.Merge({ accept: "application/json" }, headers ?? {}) ) - if(result["error"]){ + if(result["error"] !== undefined){ return <{error: string, url: string, statuscode?: number}> result } const data = result["content"] try { if (typeof data === "string") { - return JSON.parse(data) + return {content: JSON.parse(data)} } return {"content": data} } catch (e) {