From f4b2c8504de345b4fea599da27ce85c51f6c0c29 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Sat, 23 Aug 2025 09:55:24 +0000 Subject: [PATCH] appview/repo: serve appropriate 404s for non-existent files/dirs Signed-off-by: Anirudh Oppiliappan --- appview/repo/repo.go | 18 ++++++++++++++++++ 1 file(s) changed, 18 insertion(s)(+), 0 deletion(s)(-) diff --git a/appview/repo/repo.go b/appview/repo/repo.go --- a/appview/repo/repo.go +++ b/appview/repo/repo.go @@ -375,9 +375,22 @@ if !rp.config.Core.Dev { protocol = "https" } + + // if the tree path has a trailing slash, let's strip it + // so we don't 404 + treePath = strings.TrimSuffix(treePath, "/") + resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/tree/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, treePath)) if err != nil { log.Println("failed to reach knotserver", err) + return + } + + // uhhh so knotserver returns a 500 if the entry isn't found in + // the requested tree path, so let's stick to not-OK here. + // we can fix this once we build out the xrpc apis for these operations. + if resp.StatusCode != http.StatusOK { + rp.pages.Error404(w) return } @@ -525,6 +538,11 @@ resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/blob/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, filePath)) if err != nil { log.Println("failed to reach knotserver", err) + return + } + + if resp.StatusCode == http.StatusNotFound { + rp.pages.Error404(w) return } -- tangled.sh