writeAsJSON writes this error as JSON to the HTTP response.
(w http.ResponseWriter)
| 26 | |
| 27 | // writeAsJSON writes this error as JSON to the HTTP response. |
| 28 | func (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 | |
| 43 | func ClusterValidationRoundTripper(cluster string, invalidClusterValidationReporter InvalidClusterValidationReporter, next http.RoundTripper) RoundTripperFunc { |
| 44 | validateClusterValidationRoundTripperInputParameters(cluster, invalidClusterValidationReporter) |