MCPcopy
hub / github.com/cortexlabs/cortex / respondErrorCode

Function respondErrorCode

pkg/operator/endpoints/respond.go:48–73  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, code int, err error, strs ...string)

Source from the content-addressed store, hash-verified

46}
47
48func respondErrorCode(w http.ResponseWriter, r *http.Request, code int, err error, strs ...string) {
49 err = errors.Wrap(err, strs...)
50
51 if !errors.IsNoTelemetry(err) {
52 errTags := map[string]string{}
53 if clientID := r.Context().Value(ctxKeyClient); clientID != nil {
54 if clientIDStr, ok := clientID.(string); ok {
55 errTags["client_id"] = clientIDStr
56 }
57 }
58 telemetry.Error(err, errTags)
59 }
60
61 if !errors.IsNoPrint(err) {
62 operatorLogger.Error(err)
63 }
64
65 w.Header().Set("Content-Type", "application/json")
66 w.WriteHeader(code)
67
68 response := schema.ErrorResponse{
69 Kind: errors.GetKind(err),
70 Message: errors.Message(err),
71 }
72 json.NewEncoder(w).Encode(response)
73}
74
75func recoverAndRespond(w http.ResponseWriter, r *http.Request, strs ...string) {
76 if errInterface := recover(); errInterface != nil {

Callers 2

AWSAuthMiddlewareFunction · 0.85
respondErrorFunction · 0.85

Calls 8

WrapFunction · 0.92
IsNoTelemetryFunction · 0.92
ErrorFunction · 0.92
IsNoPrintFunction · 0.92
GetKindFunction · 0.92
MessageFunction · 0.92
ErrorMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected