2022-04-02 06:38:16 +00:00
|
|
|
package viewutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"mime"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HttpErr is used by many handlers to signal errors in a compact way.
|
|
|
|
// TODO: get rid of this abomination
|
2022-04-02 07:22:26 +00:00
|
|
|
func HttpErr(meta Meta, status int, name, errMsg string) {
|
2022-04-02 06:38:16 +00:00
|
|
|
meta.W.(http.ResponseWriter).Header().Set("Content-Type", mime.TypeByExtension(".html"))
|
|
|
|
meta.W.(http.ResponseWriter).WriteHeader(status)
|
|
|
|
fmt.Fprint(
|
|
|
|
meta.W,
|
|
|
|
Base(
|
|
|
|
meta,
|
|
|
|
"Error",
|
|
|
|
fmt.Sprintf(
|
|
|
|
`<main class="main-width"><p>%s. <a href="/hypha/%s">%s<a></p></main>`,
|
|
|
|
errMsg,
|
|
|
|
name,
|
2022-04-02 07:22:26 +00:00
|
|
|
meta.Lc.Get("ui.error_go_back"),
|
2022-04-02 06:38:16 +00:00
|
|
|
),
|
2022-08-14 22:36:55 +00:00
|
|
|
map[string]string{},
|
2022-04-02 06:38:16 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
2023-08-07 19:37:14 +00:00
|
|
|
|
|
|
|
// HandlerNotFound prints the simples 404 page. Use in rare places that cannot be achieved normally.
|
|
|
|
func HandlerNotFound(w http.ResponseWriter, _ *http.Request) {
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
w.Write([]byte("404 Page not found"))
|
|
|
|
}
|