More error returns added

This commit is contained in:
Melody Becker 2025-04-24 15:58:21 +02:00
parent 2b737d056c
commit 695b48ae91
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI

View file

@ -4,14 +4,17 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"git.mstar.dev/mstar/goutils/other"
) )
func SendJson(w http.ResponseWriter, data any) error { func SendJson(w http.ResponseWriter, data any) error {
encoded, err := json.Marshal(data) encoded, err := json.Marshal(data)
if err != nil { if err != nil {
return err return other.Error("webutils.SendJson", "failed to marshal data to json", err)
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", "application/json")
fmt.Fprint(w, string(encoded)) // Can't really catch here
_, _ = fmt.Fprint(w, string(encoded))
return nil return nil
} }