From 61ad99822618ec3e9f68e6c9caf185687f2e82b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Wed, 15 May 2024 22:30:37 +0200 Subject: [PATCH] wasm: print error message on missing preload file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We would previously try to json-parse the 404 error message and then abort with an json parse error. Throw a custom error instead. Change-Id: I7240294b2b107cd758f22187ae6f2b1d6923fdd7 Reviewed-by: Piotr WierciƄski (cherry picked from commit ce62b60d8590f707a0d011e6b95f1f7c729ba4e1) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/wasm/qtloader.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js index 8027dd8fa9f..8d1706eaa67 100644 --- a/src/plugins/platforms/wasm/qtloader.js +++ b/src/plugins/platforms/wasm/qtloader.js @@ -121,8 +121,13 @@ async function qtLoad(config) } } } - const fetchJsonHelper = async path => (await fetch(path)).json(); - const filesToPreload = (await Promise.all(config.qt.preload.map(fetchJsonHelper))).flat(); + const preloadFetchHelper = async (path) => { + const response = await fetch(path); + if (!response.ok) + throw new Error("Could not fetch preload file: " + path); + return response.json(); + } + const filesToPreload = (await Promise.all(config.qt.preload.map(preloadFetchHelper))).flat(); const qtPreRun = (instance) => { // Copy qt.environment to instance.ENV throwIfEnvUsedButNotExported(instance, config);