aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-07-19 19:42:39 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-07-19 19:42:39 +0200
commit3e435fc0d032a6cac0bdd15cdb138905ecdb7267 (patch)
tree5fc429dfa2e416e7e94d2a4d7064140918008b1b /pkg
parent0acfc21f54745990d094b1e6e5de463d4d8a80a3 (diff)
downloadlens-3e435fc0d032a6cac0bdd15cdb138905ecdb7267.tar.gz
lens-3e435fc0d032a6cac0bdd15cdb138905ecdb7267.tar.bz2
lens-3e435fc0d032a6cac0bdd15cdb138905ecdb7267.zip
feat: Move error from `html/template` to qtpl
Diffstat (limited to 'pkg')
-rw-r--r--pkg/ext/responses.go25
1 files changed, 7 insertions, 18 deletions
diff --git a/pkg/ext/responses.go b/pkg/ext/responses.go
index 7354395..dbad5b2 100644
--- a/pkg/ext/responses.go
+++ b/pkg/ext/responses.go
@@ -6,21 +6,16 @@ import (
"github.com/valyala/fasthttp"
- "git.sr.ht/~gabrielgio/img"
+ "git.sr.ht/~gabrielgio/img/templates"
)
var (
- ContentTypeJSON = []byte("application/json")
- ContentTypeHTML = []byte("text/html")
- ContentTypeMARKDOWN = []byte("text/markdown")
- ContentTypeJPEG = []byte("image/jpeg")
+ ContentTypeHTML = []byte("text/html")
)
func NotFoundHTML(ctx *fasthttp.RequestCtx) {
- ctx.Response.Header.SetContentType("text/html")
- //nolint:errcheck
- img.Render(ctx, "error.html", &img.HTMLView[string]{
- Data: "NotFound",
+ templates.WritePageTemplate(ctx, &templates.ErrorPage{
+ Err: "Not Found",
})
}
@@ -33,16 +28,10 @@ func NotFound(ctx *fasthttp.RequestCtx) {
}
func InternalServerError(ctx *fasthttp.RequestCtx, err error) {
- ctx.Response.Header.SetContentType("text/html")
- message := fmt.Sprintf("Internal Server Error:\n%+v", err)
- //nolint:errcheck
- respErr := img.Render(ctx, "error.html", &img.HTMLView[string]{
- Data: message,
+ ctx.Response.SetStatusCode(500)
+ templates.WritePageTemplate(ctx, &templates.ErrorPage{
+ Err: fmt.Sprintf("Internal Server Error:\n%s", err.Error()),
})
-
- if respErr != nil {
- fmt.Println(respErr.Error())
- }
}
func NoContent(ctx *fasthttp.RequestCtx) {