package main import "net/http" func handler1(w http.ResponseWriter, req *http.Request) { err := foo(req) if err != nil { http.Error(w, "foo", http.StatusInternalServerError) } _, _ = w.Write([]byte("all good")) w.WriteHeader(http.StatusCreated) } func handler2(w http.ResponseWriter, req *http.Request) { err := foo(req) if err != nil { http.Error(w, "foo", http.StatusInternalServerError) return } _, _ = w.Write([]byte("all good")) w.WriteHeader(http.StatusCreated) } func foo(req *http.Request) error { return nil }