Skip to content

Commit 88627e9

Browse files
committed
Log stack upon panics
1 parent 71c1750 commit 88627e9

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

middleware/recoverer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package middleware
22

33
import (
44
"fmt"
5-
"net/http"
6-
75
"github.com/cloudhut/common/rest"
86
"go.uber.org/zap"
7+
"go.uber.org/zap/zapcore"
8+
"net/http"
99
)
1010

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

0 commit comments

Comments
 (0)