Skip to content

Commit 9857737

Browse files
Better error messages when Bubblewrap can't fetch manifest due to being served HTML
1 parent 339d54d commit 9857737

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

apps/pwabuilder-google-play/services/bubbleWrapper.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,22 @@ export class BubbleWrapper {
179179
private async generateTwaProject(): Promise<TwaManifest> {
180180
const twaGenerator = new TwaGenerator();
181181
const twaManifest = this.createTwaManifest(this.apkSettings);
182-
await twaGenerator.createTwaProject(
183-
this.projectDirectory,
184-
twaManifest,
185-
new ConsoleLog()
186-
);
182+
try {
183+
await twaGenerator.createTwaProject(
184+
this.projectDirectory,
185+
twaManifest,
186+
new ConsoleLog()
187+
);
188+
} catch (error) {
189+
// Better handling for errors where fetching JSON (usually the web manifest) returns HTML result.
190+
// Example: https://github.com/pwa-builder/PWABuilder/issues/5376
191+
if (error instanceof Error && error.message.includes("Unexpected token '<'")) {
192+
const badJsonMessage = `Your web app returned HTML instead of JSON. Make sure your web manifest can be loaded directly. Try opening your web app in the browser, open F12 dev tools -> Application -> Manifest, and ensure your web manifest is loading properly. Error details: ${error.message}`;
193+
this.dispatchProgressEvent(badJsonMessage, "error");
194+
}
195+
196+
throw error;
197+
}
187198
return twaManifest;
188199
}
189200

0 commit comments

Comments
 (0)