Monorepo for Tangled tangled.org

appview/repo: serve appropriate 404s for non-existent files/dirs

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.sh>

anirudh.fi f4b2c850 a7d7a96a

verified
Changed files
+18
appview
repo
+18
appview/repo/repo.go
··· 375 375 if !rp.config.Core.Dev { 376 376 protocol = "https" 377 377 } 378 + 379 + // if the tree path has a trailing slash, let's strip it 380 + // so we don't 404 381 + treePath = strings.TrimSuffix(treePath, "/") 382 + 378 383 resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/tree/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, treePath)) 379 384 if err != nil { 380 385 log.Println("failed to reach knotserver", err) 386 + return 387 + } 388 + 389 + // uhhh so knotserver returns a 500 if the entry isn't found in 390 + // the requested tree path, so let's stick to not-OK here. 391 + // we can fix this once we build out the xrpc apis for these operations. 392 + if resp.StatusCode != http.StatusOK { 393 + rp.pages.Error404(w) 381 394 return 382 395 } 383 396 ··· 525 538 resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/blob/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, filePath)) 526 539 if err != nil { 527 540 log.Println("failed to reach knotserver", err) 541 + return 542 + } 543 + 544 + if resp.StatusCode == http.StatusNotFound { 545 + rp.pages.Error404(w) 528 546 return 529 547 } 530 548