More error returns added
This commit is contained in:
parent
2b737d056c
commit
695b48ae91
1 changed files with 5 additions and 2 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue