From eda45221cd94ca200b4007fa91c826857bb608e3 Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 19 Mar 2024 18:25:42 +1300 Subject: [PATCH] repo: on any failure to build repo page, redirect to gitea page --- page_repository.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/page_repository.go b/page_repository.go index 970700c..a62d98d 100644 --- a/page_repository.go +++ b/page_repository.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "html" + "log" "net/http" "net/url" "strings" @@ -16,7 +17,8 @@ func (this *Application) Repopage(w http.ResponseWriter, r *http.Request, repoNa readme, err := this.gitea.RepoFile(ctx, repoName, `README.md`) if err != nil { - this.internalError(w, r, fmt.Errorf("loading README.md: %w", err)) + log.Printf("%s %s: %s", r.Method, r.URL.Path, err) + http.Redirect(w, r, repoURL, http.StatusTemporaryRedirect) return } @@ -55,7 +57,8 @@ func (this *Application) Repopage(w http.ResponseWriter, r *http.Request, repoNa readmeHtml, err := this.gitea.RenderMarkdown(ctx, repoName, strings.Join(lines, "\n")) if err != nil { - this.internalError(w, r, fmt.Errorf("rendering markdown: %w", err)) + log.Printf("%s %s: %s", r.Method, r.URL.Path, fmt.Errorf("rendering markdown: %w", err)) + http.Redirect(w, r, repoURL, http.StatusTemporaryRedirect) return } @@ -63,7 +66,8 @@ func (this *Application) Repopage(w http.ResponseWriter, r *http.Request, repoNa images, err := this.gitea.ImageFilesForRepo(ctx, repoName) if err != nil { - this.internalError(w, r, fmt.Errorf("listing images: %w", err)) + log.Printf("%s %s: %s", r.Method, r.URL.Path, fmt.Errorf("listing images: %w", err)) + http.Redirect(w, r, repoURL, http.StatusTemporaryRedirect) return }