Why this matters
Keeps responses predictable for clients and aligns with platform conventions.
Return appropriate status codes and prefer http.StatusText(status) (or a consistent JSON error schema) rather than inventing custom reason phrases.
Keeps responses predictable for clients and aligns with platform conventions.
Side-by-side examples engineers can pattern-match during review.
w.WriteHeader(500)
_, _ = w.Write([]byte("Server go-boom"))http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
// or JSON: w.WriteHeader(http.StatusBadRequest); json.NewEncoder(w).Encode(map[string]string{"error": http.StatusText(http.StatusBadRequest)})w.WriteHeader(499); w.Write([]byte("Oops"))http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)From the same buckets as this rule.