fix(webui): display an error page in all error cases
All checks were successful
main / main (push) Successful in 1m48s
main / deploy (push) Has been skipped
main / publish (push) Has been skipped

This commit is contained in:
Julien Dessaux 2025-04-19 15:19:21 +02:00
parent c483d909f9
commit bb11b870d6
Signed by: adyxax
GPG key ID: F92E51B86E07177E
5 changed files with 11 additions and 6 deletions

View file

@ -15,7 +15,7 @@ func errorResponse(w http.ResponseWriter, r *http.Request, status int, err error
StatusText string StatusText string
} }
render(w, errorTemplates, status, &ErrorData{ render(w, errorTemplates, status, &ErrorData{
Page: makePage(r, &Page{Title: "Error", Section: "error"}), Page: &Page{Title: "Error", Section: "error"},
Err: err, Err: err,
Status: status, Status: status,
StatusText: http.StatusText(status), StatusText: http.StatusText(status),

View file

@ -3,7 +3,7 @@
{{ if ne .Account.PasswordReset nil }} {{ if ne .Account.PasswordReset nil }}
<h2>Password Reset</h2> <h2>Password Reset</h2>
<article> <article>
Direct the user to <a href="/account/{{ .Account.Id }}/reset/{{ .Account.PasswordReset }}">/account/{{ .Account.Id }}/reset/{{ .Account.PasswordReset }}</a> so that they can create their password. Direct the user to <a href="/accounts/{{ .Account.Id }}/reset/{{ .Account.PasswordReset }}">/accounts/{{ .Account.Id }}/reset/{{ .Account.PasswordReset }}</a> so that they can create their password.
</article> </article>
{{ end }} {{ end }}
<h2>Status</h2> <h2>Status</h2>

View file

@ -19,6 +19,11 @@
<i class="material-symbols-outlined">login</i> <i class="material-symbols-outlined">login</i>
<span>Login</span> <span>Login</span>
</a> </a>
{{ else if eq .Page.Section "error" }}
<a href="/">
<i class="material-symbols-outlined">mountain_flag</i>
<span>TfStated</span>
</a>
{{ else }} {{ else }}
<a href="/states"{{ if eq .Page.Section "states" }} class="primary"{{ end}}> <a href="/states"{{ if eq .Page.Section "states" }} class="primary"{{ end}}>
<i class="material-symbols-outlined">home_storage</i> <i class="material-symbols-outlined">home_storage</i>

View file

@ -18,7 +18,7 @@ var loginTemplate = template.Must(template.ParseFS(htmlFS, "html/base.html", "ht
var validUsername = regexp.MustCompile(`^[a-zA-Z]\w*$`) var validUsername = regexp.MustCompile(`^[a-zA-Z]\w*$`)
type loginPage struct { type loginPage struct {
Page Page *Page
Forbidden bool Forbidden bool
Username string Username string
} }
@ -34,7 +34,7 @@ func handleLoginGET() http.Handler {
} }
render(w, loginTemplate, http.StatusOK, loginPage{ render(w, loginTemplate, http.StatusOK, loginPage{
Page: Page{Title: "Login", Section: "login"}, Page: &Page{Title: "Login", Section: "login"},
}) })
}) })
} }
@ -42,7 +42,7 @@ func handleLoginGET() http.Handler {
func handleLoginPOST(db *database.DB) http.Handler { func handleLoginPOST(db *database.DB) http.Handler {
renderForbidden := func(w http.ResponseWriter, username string) { renderForbidden := func(w http.ResponseWriter, username string) {
render(w, loginTemplate, http.StatusForbidden, loginPage{ render(w, loginTemplate, http.StatusForbidden, loginPage{
Page: Page{Title: "Login", Section: "login"}, Page: &Page{Title: "Login", Section: "login"},
Forbidden: true, Forbidden: true,
Username: username, Username: username,
}) })

View file

@ -284,7 +284,7 @@ button:hover {
gap: 4px; gap: 4px;
} }
.flex-row { .flex-row {
align-items: start; align-items: center;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
gap: 16px; gap: 16px;