Skip to content

Commit

Permalink
Log the panic message even if it's not of type error (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenmcc authored and jprobinson committed Nov 12, 2019
1 parent f990600 commit aca1015
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions server/kit/kitserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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,
Expand Down

0 comments on commit aca1015

Please sign in to comment.