Skip to content

Commit dc33820

Browse files
Better handles manifest 404s
1 parent d70e0a5 commit dc33820

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

apps/pwabuilder/Services/ManifestDetector.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,25 @@ public ManifestDetector(WebStringCache webStringCache, IPuppeteerService puppete
156156
return null;
157157
}
158158

159-
var manifest = JsonSerializer.Deserialize<JsonElement>(manifestJson);
159+
// Make sure the JSON doesn't start with `<`, which indicates an HTML page (probably a 404). This tends to happen often with apps that
160+
// have a manifest link but the link is broken. e.g. https://github.com/pwa-builder/PWABuilder/issues/5094
161+
if (manifestJson.TrimStart().StartsWith('<'))
162+
{
163+
logger.LogWarning("Manifest at {manifestUrl} appears to be HTML, not JSON. {manifestJsonResponse}", manifestUrl, manifestJson);
164+
return null;
165+
}
166+
167+
JsonElement manifest;
168+
try
169+
{
170+
manifest = JsonSerializer.Deserialize<JsonElement>(manifestJson);
171+
}
172+
catch (Exception jsonError)
173+
{
174+
logger.LogWarning(jsonError, "Error parsing manifest JSON at {manifestUrl}.", manifestUrl);
175+
return null;
176+
}
177+
160178
return new ManifestDetection
161179
{
162180
Url = manifestUrl,

0 commit comments

Comments
 (0)