morz-infoboard/server/backend/internal/httpapi/errors.go
Jesko Anschütz f8a57b3e6b Bereinige signalstarke Linter-Funde
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-03-22 17:56:56 +01:00

35 lines
632 B
Go

package httpapi
import (
"encoding/json"
"net/http"
)
type errorEnvelope struct {
Error apiError `json:"error"`
}
type apiError struct {
Code string `json:"code"`
Message string `json:"message"`
Details any `json:"details"`
}
func writeError(w http.ResponseWriter, status int, code, message string, details any) {
writeJSON(w, status, errorEnvelope{
Error: apiError{
Code: code,
Message: message,
Details: details,
},
})
}
func decodeJSON(r *http.Request, dest any) error {
defer func() {
if err := r.Body.Close(); err != nil {
return
}
}()
return json.NewDecoder(r.Body).Decode(dest)
}