Skip to content

Commit 2943a32

Browse files
Bl1tz23aldas
authored andcommitted
restore originalWriter in case of panic inside echoHandlerFuncWrapper.ServeHTTP method
1 parent b643e68 commit 2943a32

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

middleware/timeout.go

+9
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ func (t echoHandlerFuncWrapper) ServeHTTP(rw http.ResponseWriter, r *http.Reques
9292
originalWriter := t.ctx.Response().Writer
9393
t.ctx.Response().Writer = rw
9494

95+
// in case of panic we restore original writer and call panic again
96+
// so it could be handled with global middleware Recover()
97+
defer func() {
98+
if err := recover(); err != nil {
99+
t.ctx.Response().Writer = originalWriter
100+
panic(err)
101+
}
102+
}()
103+
95104
err := t.handler(t.ctx)
96105
if ctxErr := r.Context().Err(); ctxErr == context.DeadlineExceeded {
97106
if err != nil && t.errHandler != nil {

0 commit comments

Comments
 (0)