MCPcopy
hub / github.com/grafana/dskit / writeAsJSON

Method writeAsJSON

middleware/http_cluster.go:28–41  ·  view source on GitHub ↗

writeAsJSON writes this error as JSON to the HTTP response.

(w http.ResponseWriter)

Source from the content-addressed store, hash-verified

26
27// writeAsJSON writes this error as JSON to the HTTP response.
28func (e *clusterValidationError) writeAsJSON(w http.ResponseWriter) {
29 data, err := json.Marshal(e)
30 if err != nil {
31 http.Error(w, err.Error(), http.StatusInternalServerError)
32 return
33 }
34
35 w.Header().Set("Content-Type", "application/json")
36 w.WriteHeader(http.StatusNetworkAuthenticationRequired)
37 // We ignore errors here, because we cannot do anything about them.
38 // Write will trigger sending Status code, so we cannot send a different status code afterwards.
39 // Also, this isn't internal error, but error communicating with client.
40 _, _ = w.Write(data)
41}
42
43func ClusterValidationRoundTripper(cluster string, invalidClusterValidationReporter InvalidClusterValidationReporter, next http.RoundTripper) RoundTripperFunc {
44 validateClusterValidationRoundTripperInputParameters(cluster, invalidClusterValidationReporter)

Callers 2

Calls 6

SetMethod · 0.65
MarshalMethod · 0.45
ErrorMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
WriteMethod · 0.45

Tested by 1