Skip to content

Commit e55b377

Browse files
committed
Show a clearer error message if the initial UI load fails
This should only ever be possible on the initial page load, if no network connection is available, since after that point the service worker will always have the UI cached.
1 parent e0bdc72 commit e55b377

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,30 @@ if (!amMainInstance) {
235235
contents.reload();
236236
});
237237
});
238+
239+
contents.on('did-fail-load', (
240+
_event,
241+
code,
242+
description,
243+
url,
244+
isMainFrame
245+
) => {
246+
if (!isMainFrame) return; // Just in case
247+
248+
const { protocol, host, pathname } = new URL(url);
249+
const baseURL = `${protocol}//${host}${pathname}`;
250+
251+
showErrorAlert(
252+
"UI load failed",
253+
`The HTTP Toolkit UI could not be loaded from\n${baseURL}.` +
254+
"\n\n" +
255+
`${description} (${code})`
256+
);
257+
258+
setTimeout(() => {
259+
contents.reload();
260+
}, 2000);
261+
});
238262
});
239263

240264
function checkForUnsafeNavigation(url: URL) {

0 commit comments

Comments
 (0)