Skip to content

Commit

Permalink
restore originalWriter in case of panic inside echoHandlerFuncWrapper…
Browse files Browse the repository at this point in the history
….ServeHTTP method
  • Loading branch information
Bl1tz23 committed Apr 28, 2021
1 parent 6430665 commit 48fa624
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions middleware/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ func (t echoHandlerFuncWrapper) ServeHTTP(rw http.ResponseWriter, r *http.Reques
originalWriter := t.ctx.Response().Writer
t.ctx.Response().Writer = rw

// in case of panic we restore original writer and call panic again
// so it could be handled with global middleware Recover()
defer func() {
if err := recover(); err != nil {
t.ctx.Response().Writer = originalWriter
panic(err)
}
}()

err := t.handler(t.ctx)
if ctxErr := r.Context().Err(); ctxErr == context.DeadlineExceeded {
if err != nil && t.errHandler != nil {
Expand Down

0 comments on commit 48fa624

Please sign in to comment.