Skip to content

Commit

Permalink
feat: recover middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
miyataka committed Jan 1, 2024
1 parent 9b54d70 commit 332ba5f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions recover_middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package minimalmux

import (
"fmt"
"net/http"
)

func RecoverMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if r := recover(); r != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Internal Server Error")
}
}()
next.ServeHTTP(w, r)
})
}

0 comments on commit 332ba5f

Please sign in to comment.