MCPcopy
hub / github.com/dnote/dnote / handleJSONError

Function handleJSONError

pkg/server/controllers/helpers.go:252–266  ·  view source on GitHub ↗

handleJSONError logs the error and responds with the given status code with a generic status text

(w http.ResponseWriter, err error, msg string)

Source from the content-addressed store, hash-verified

250
251// handleJSONError logs the error and responds with the given status code with a generic status text
252func handleJSONError(w http.ResponseWriter, err error, msg string) {
253 statusCode := getStatusCode(err)
254
255 rootErr := errors.Cause(err)
256
257 var respText string
258 if pErr, ok := rootErr.(views.PublicError); ok {
259 respText = pErr.Public()
260 } else {
261 respText = http.StatusText(statusCode)
262 }
263
264 logError(err, msg)
265 http.Error(w, respText, statusCode)
266}
267
268// respondWithSession makes a HTTP response with the session from the user with the given userID.
269// It sets the HTTP-Only cookie for browser clients and also sends a JSON response for non-browser clients.

Callers 14

respondWithSessionFunction · 0.85
respondJSONFunction · 0.85
V3IndexMethod · 0.85
V3ShowMethod · 0.85
V3CreateMethod · 0.85
V3UpdateMethod · 0.85
V3DeleteMethod · 0.85
V3IndexMethod · 0.85
V3ShowMethod · 0.85
V3CreateMethod · 0.85
V3DeleteMethod · 0.85
V3UpdateMethod · 0.85

Calls 4

getStatusCodeFunction · 0.85
logErrorFunction · 0.85
PublicMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected