diff --git a/main.go b/main.go index ef24e61..585c0b2 100644 --- a/main.go +++ b/main.go @@ -167,6 +167,8 @@ func requestPerMinute() { func beforeAll(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { + defer panicHandler(w) + if req.Method != "GET" && req.Method != "HEAD" { io.WriteString(w, "Only GET and HEAD requests are allowed.") return diff --git a/utils.go b/utils.go index 781453a..6db8c0f 100644 --- a/utils.go +++ b/utils.go @@ -55,3 +55,10 @@ func RelativeUrl(in string) (newurl string) { segment_url.Path = path_prefix + segment_url.Path return segment_url.RequestURI() } + +func panicHandler(w http.ResponseWriter) { + if r := recover(); r != nil { + log.Printf("Panic: %v", r) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + } +}