Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return meaningful response if index.html is not found #213

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,20 @@ export const createHappWindow = (
const uriWithoutProtocol = request.url.slice('webhapp://'.length);
const filePathComponents = uriWithoutProtocol.split('/').slice(1);
const filePath = path.join(...filePathComponents);
const response = await net.fetch(
url.pathToFileURL(path.join(appUiDir, 'assets', filePath)).toString(),
);

let response: Response;
try {
response = await net.fetch(
url.pathToFileURL(path.join(appUiDir, 'assets', filePath)).toString(),
);
} catch (e) {
if (filePath === 'index.html') {
return new Response(
'No index.html found. If you are the developer of this app, make sure that the index.html is located at the root level of your UI assets.',
);
}
throw new Error(`Asset ${filePath} not found: ${e}`);
}

const expectedHash = uiHashes[filePath];
if (!expectedHash) {
Expand Down