Gofmt recover.go

This commit is contained in:
jordi fita mas 2023-01-22 20:37:34 +01:00
parent 6f2da865c0
commit 7e5e6121ac
1 changed files with 9 additions and 9 deletions

View File

@ -1,10 +1,10 @@
package pkg
import (
"fmt"
"log"
"net/http"
"runtime"
"log"
"fmt"
)
func Recoverer(next http.Handler) http.Handler {
@ -12,18 +12,18 @@ func Recoverer(next http.Handler) http.Handler {
defer func() {
if r := recover(); r != nil {
if r == http.ErrAbortHandler {
panic(r);
panic(r)
}
err, ok := r.(error)
if ! ok {
err = fmt.Errorf("%v", r);
if !ok {
err = fmt.Errorf("%v", r)
}
stack := make([]byte, 4 << 10);
stack := make([]byte, 4<<10)
length := runtime.Stack(stack, true)
log.Printf("PANIC - %v %s", err, stack[:length])
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}();
next.ServeHTTP(w, r);
});
}()
next.ServeHTTP(w, r)
})
}