Skip to content

Commit

Permalink
Log stack upon panics
Browse files Browse the repository at this point in the history
  • Loading branch information
weeco committed Nov 12, 2020
1 parent 71c1750 commit 88627e9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions middleware/recoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package middleware

import (
"fmt"
"net/http"

"github.com/cloudhut/common/rest"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"net/http"
)

// Recoverer middleware logs unhandled panics and tries to continue running the API
Expand All @@ -20,10 +20,13 @@ func (rec *Recoverer) Wrap(next http.Handler) http.Handler {
if err := recover(); err != nil {
w.Header().Set("Connection", "close")
restErr := &rest.Error{
Err: fmt.Errorf("There was a panic! %s", err),
Err: fmt.Errorf("there was a panic: %s", err),
Status: http.StatusInternalServerError,
Message: "Internal Server Error",
IsSilent: false,
InternalLogs: []zapcore.Field{
zap.Stack("stack"),
},
}
rest.SendRESTError(w, r, rec.Logger, restErr)
}
Expand Down

0 comments on commit 88627e9

Please sign in to comment.