repo: on any failure to build repo page, redirect to gitea page

This commit is contained in:
mappu 2024-03-19 18:25:42 +13:00
parent bd04f5c117
commit eda45221cd
1 changed files with 7 additions and 3 deletions

View File

@ -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
}