diff --git a/server/kit/kitserver.go b/server/kit/kitserver.go index 3d7486eaf..f28f66014 100644 --- a/server/kit/kitserver.go +++ b/server/kit/kitserver.go @@ -161,12 +161,7 @@ func NewServer(svc Service) *Server { func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer func() { if x := recover(); x != nil { - var err error - if e, ok := x.(error); ok { - err = e - } - - s.logger.Log("error", err, "message", "the server encountered a panic", "stacktrace", string(debug.Stack())) + s.logger.Log("error", x, "message", "the server encountered a panic", "stacktrace", string(debug.Stack())) w.WriteHeader(http.StatusInternalServerError) _, werr := w.Write([]byte(http.StatusText(http.StatusInternalServerError))) @@ -179,6 +174,10 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + var err error + if e, ok := x.(error); ok { + err = e + } s.errs.Report(errorreporting.Entry{ Req: r, Error: err,