MCPcopy Create free account
hub / github.com/daodst/chat / UnmarshalJSON

Function UnmarshalJSON

clientapi/httputil/httputil.go:42–60  ·  view source on GitHub ↗
(body []byte, iface interface{})

Source from the content-addressed store, hash-verified

40}
41
42func UnmarshalJSON(body []byte, iface interface{}) *util.JSONResponse {
43 if !utf8.Valid(body) {
44 return &util.JSONResponse{
45 Code: http.StatusBadRequest,
46 JSON: jsonerror.NotJSON("Body contains invalid UTF-8"),
47 }
48 }
49
50 if err := json.Unmarshal(body, iface); err != nil {
51 // TODO: We may want to suppress the Error() return in production? It's useful when
52 // debugging because an error will be produced for both invalid/malformed JSON AND
53 // valid JSON with incorrect types for values.
54 return &util.JSONResponse{
55 Code: http.StatusBadRequest,
56 JSON: jsonerror.BadJSON("The request body could not be decoded into valid JSON. " + err.Error()),
57 }
58 }
59 return nil
60}

Callers 1

UnmarshalJSONRequestFunction · 0.85

Calls 2

ValidMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected