mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 07:11:02 +00:00
add recovery in top level handler
This commit is contained in:
parent
07a0e12fd6
commit
0385e60190
1 changed files with 11 additions and 0 deletions
11
handler.go
11
handler.go
|
|
@ -29,6 +29,7 @@ import (
|
|||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -138,6 +139,16 @@ func (h *Handler) methodNotAllowedHandler(w http.ResponseWriter, r *http.Request
|
|||
|
||||
// ServeHTTP handles an HTTP request.
|
||||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
stack := debug.Stack()
|
||||
msg := "PANIC: %s\n%s"
|
||||
fmt.Fprintf(h.LogOutput, msg, err, stack)
|
||||
fmt.Fprintf(w, msg, err, stack)
|
||||
}
|
||||
}()
|
||||
|
||||
t := time.Now()
|
||||
h.Router.ServeHTTP(w, r)
|
||||
dif := time.Since(t)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue