| 46 | } |
| 47 | |
| 48 | func 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 | |
| 75 | func recoverAndRespond(w http.ResponseWriter, r *http.Request, strs ...string) { |
| 76 | if errInterface := recover(); errInterface != nil { |