From 36ebdfb441901550a47cdc75a2373513ea5c0bfe Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Sat, 27 Jan 2024 14:05:15 +0100 Subject: [PATCH] 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 Co-authored-by: Dmitry Gozman --- packages/trace-viewer/src/ui/sourceTab.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/trace-viewer/src/ui/sourceTab.tsx b/packages/trace-viewer/src/ui/sourceTab.tsx index 50d96f8ee3..9e26bf13a9 100644 --- a/packages/trace-viewer/src/ui/sourceTab.tsx +++ b/packages/trace-viewer/src/ui/sourceTab.tsx @@ -67,7 +67,10 @@ export const SourceTab: React.FunctionComponent<{ let response = await fetch(`sha1/src@${sha1}.txt`); if (response.status === 404) response = await fetch(`file?path=${encodeURIComponent(file)}`); - source.content = await response.text(); + if (response.status >= 400) + source.content = ``; + else + source.content = await response.text(); } catch { source.content = ``; }