MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / writeHTTPErrorResponse

Function writeHTTPErrorResponse

management/middleware.go:53–69  ·  view source on GitHub ↗

writeErrorResponse will respond to the eyeball with basic HTTP JSON payloads with validation failure information

(w http.ResponseWriter, errResp managementError)

Source from the content-addressed store, hash-verified

51
52// writeErrorResponse will respond to the eyeball with basic HTTP JSON payloads with validation failure information
53func writeHTTPErrorResponse(w http.ResponseWriter, errResp managementError) {
54 w.Header().Set("Content-Type", "application/json")
55 w.WriteHeader(http.StatusBadRequest)
56 err := json.NewEncoder(w).Encode(managementErrorResponse{
57 Success: false,
58 Errors: []managementError{errResp},
59 })
60 // we have already written the header, so write a basic error response if unable to encode the error
61 if err != nil {
62 // fallback to text message
63 http.Error(w, fmt.Sprintf(
64 "%d %s",
65 http.StatusBadRequest,
66 http.StatusText(http.StatusBadRequest),
67 ), http.StatusBadRequest)
68 }
69}

Callers 1

Calls 5

SetMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
EncodeMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected