MCPcopy
hub / github.com/perkeep/perkeep / ServeJSONError

Function ServeJSONError

internal/httputil/httputil.go:258–269  ·  view source on GitHub ↗

ServeJSONError sends a JSON error response to rw for the provided error value.

(rw http.ResponseWriter, err interface{})

Source from the content-addressed store, hash-verified

256// ServeJSONError sends a JSON error response to rw for the provided
257// error value.
258func ServeJSONError(rw http.ResponseWriter, err interface{}) {
259 code := 500
260 if i, ok := err.(httpCoder); ok {
261 code = i.HTTPCode()
262 }
263 msg := fmt.Sprint(err)
264 log.Printf("Sending error %v to client for: %v", code, msg)
265 ReturnJSONCode(rw, code, map[string]interface{}{
266 "error": msg,
267 "errorType": http.StatusText(code),
268 })
269}
270
271// DecodeJSON decodes the JSON in res.Body into dest and then closes
272// res.Body.

Callers 11

serveRecentPermanodesMethod · 0.92
serveClaimsMethod · 0.92
serveSignerAttrValueMethod · 0.92
serveEdgesToMethod · 0.92
serveQueryMethod · 0.92
serveSignerPathsMethod · 0.92
serveDescribeMethod · 0.92
discoveryHelperFunction · 0.92
serveUploadHelperMethod · 0.92
RecoverJSONFunction · 0.85

Calls 3

ReturnJSONCodeFunction · 0.85
PrintfMethod · 0.80
HTTPCodeMethod · 0.65

Tested by

no test coverage detected