MCPcopy
hub / github.com/cubefs/cubefs / ServeResponse

Method ServeResponse

objectnode/result_error.go:118–136  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

116}
117
118func (ec *ErrorCode) ServeResponse(w http.ResponseWriter, r *http.Request) {
119 // write status code to request context,
120 // traceMiddleWare send exception request to prometheus via status code
121 SetResponseStatusCode(r, strconv.Itoa(ec.StatusCode))
122 SetResponseErrorMessage(r, ec.ErrorMessage)
123
124 errorResponse := ErrorResponse{
125 Code: ec.ErrorCode,
126 Message: ec.ErrorMessage,
127 Resource: r.URL.String(),
128 RequestId: GetRequestID(r),
129 }
130 response, _ := xml.Marshal(errorResponse)
131 response = append([]byte(strings.TrimSuffix(xml.Header, "\n")), response...)
132 w.Header().Set(ContentType, ValueContentTypeXML)
133 w.Header().Set(ContentLength, strconv.Itoa(len(response)))
134 w.WriteHeader(ec.StatusCode)
135 _, _ = w.Write(response)
136}
137
138func (ec *ErrorCode) Error() string {
139 return ec.ErrorMessage

Callers 4

traceMiddlewareMethod · 0.80
corsMiddlewareMethod · 0.80
errorResponseMethod · 0.80

Calls 9

SetResponseStatusCodeFunction · 0.85
SetResponseErrorMessageFunction · 0.85
GetRequestIDFunction · 0.85
StringMethod · 0.65
MarshalMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65
HeaderMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected