fix: provisional fix for Trace Viewer source 404 (#29192)

Motivation: Sometimes the files are not available anymore on the Service
Worker side. The Trace Viewer frontend then falls back to `file?path=`
and uses its response, no matter what the response status is.

This patch checks for the response status code before using its
response.

e.g. https://github.com/microsoft/playwright-dotnet/issues/2775 after
some time / and some other reports.

---------

Signed-off-by: Max Schmitt <max@schmitt.mx>
Co-authored-by: Dmitry Gozman <dgozman@gmail.com>
This commit is contained in:
Max Schmitt 2024-01-27 14:05:15 +01:00 committed by GitHub
parent 5ee7179b13
commit 36ebdfb441
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,6 +67,9 @@ export const SourceTab: React.FunctionComponent<{
let response = await fetch(`sha1/src@${sha1}.txt`);
if (response.status === 404)
response = await fetch(`file?path=${encodeURIComponent(file)}`);
if (response.status >= 400)
source.content = `<Unable to read "${file}">`;
else
source.content = await response.text();
} catch {
source.content = `<Unable to read "${file}">`;