feat: add panic handlers

This commit is contained in:
Stefan Martinov 2019-09-06 17:26:02 +02:00
parent f7f3b8096e
commit 5ce4cccbea
2 changed files with 13 additions and 0 deletions

View File

@ -84,6 +84,12 @@ func (s *socketServer) writeResponse(conn net.Conn, reply []byte) {
}
func (s *socketServer) handleConnection(conn net.Conn) {
defer func() {
if r := recover(); r != nil {
Log.Error("panic in handle connection", zap.String("error", fmt.Sprint(r)))
}
}()
Log.Debug("socketServer.handleConnection")
status.M.NumSocketsGauge.WithLabelValues(conn.RemoteAddr().String()).Inc()

View File

@ -1,6 +1,7 @@
package server
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
@ -28,6 +29,12 @@ func NewWebServer(path string, r *repo.Repo) http.Handler {
}
func (s *webServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
if r := recover(); r != nil {
Log.Error("panic in handle connection", zap.String("error", fmt.Sprint(r)))
}
}()
if r.Body == nil {
http.Error(w, "no body", http.StatusBadRequest)
return