aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/config/handler.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-06-08 00:01:44 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-06-08 00:01:44 +0200
commit6079b1d963f34ada5c4b25363f2319901e283936 (patch)
treef7f93616eb3dacfcebee486fe7542ec3adfb3950 /pkg/handler/config/handler.go
parente9098e00fb6339b759df5b0df2e086cef8a7ce83 (diff)
downloadcerrado-6079b1d963f34ada5c4b25363f2319901e283936.tar.gz
cerrado-6079b1d963f34ada5c4b25363f2319901e283936.tar.bz2
cerrado-6079b1d963f34ada5c4b25363f2319901e283936.zip
feat: Add error handling
Diffstat (limited to 'pkg/handler/config/handler.go')
-rw-r--r--pkg/handler/config/handler.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/pkg/handler/config/handler.go b/pkg/handler/config/handler.go
index 30f4283..c43b54d 100644
--- a/pkg/handler/config/handler.go
+++ b/pkg/handler/config/handler.go
@@ -3,7 +3,6 @@ package config
import (
"bytes"
"encoding/json"
- "log/slog"
"net/http"
"github.com/alecthomas/chroma/v2/formatters/html"
@@ -11,6 +10,7 @@ import (
"github.com/alecthomas/chroma/v2/styles"
"git.gabrielgio.me/cerrado/pkg/config"
+ "git.gabrielgio.me/cerrado/pkg/ext"
"git.gabrielgio.me/cerrado/templates"
)
@@ -21,8 +21,8 @@ type (
}
)
-func ConfigFile(configRepo configurationRepository) func(http.ResponseWriter, *http.Request) {
- return func(w http.ResponseWriter, _ *http.Request) {
+func ConfigFile(configRepo configurationRepository) ext.ErrorRequestHandler {
+ return func(w http.ResponseWriter, _ *http.Request) error {
config := struct {
RootReadme string
@@ -34,8 +34,7 @@ func ConfigFile(configRepo configurationRepository) func(http.ResponseWriter, *h
b, err := json.MarshalIndent(config, "", " ")
if err != nil {
- slog.Error("Error parsing json", "error", err)
- return
+ return err
}
lexer := lexers.Get("json")
@@ -45,15 +44,13 @@ func ConfigFile(configRepo configurationRepository) func(http.ResponseWriter, *h
)
iterator, err := lexer.Tokenise(nil, string(b))
if err != nil {
- slog.Error("Error tokenise", "error", err)
- return
+ return err
}
var code bytes.Buffer
err = formatter.Format(&code, style, iterator)
if err != nil {
- slog.Error("Error format", "error", err)
- return
+ return err
}
hello := &templates.ConfigPage{
@@ -61,5 +58,6 @@ func ConfigFile(configRepo configurationRepository) func(http.ResponseWriter, *h
}
templates.WritePageTemplate(w, hello)
+ return nil
}
}