mirror of
https://github.com/foomo/contentserver.git
synced 2025-10-16 12:25:44 +00:00
feat: add panic handlers
This commit is contained in:
parent
f7f3b8096e
commit
5ce4cccbea
@ -84,6 +84,12 @@ func (s *socketServer) writeResponse(conn net.Conn, reply []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *socketServer) handleConnection(conn net.Conn) {
|
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")
|
Log.Debug("socketServer.handleConnection")
|
||||||
status.M.NumSocketsGauge.WithLabelValues(conn.RemoteAddr().String()).Inc()
|
status.M.NumSocketsGauge.WithLabelValues(conn.RemoteAddr().String()).Inc()
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@ -28,6 +29,12 @@ func NewWebServer(path string, r *repo.Repo) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *webServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
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 {
|
if r.Body == nil {
|
||||||
http.Error(w, "no body", http.StatusBadRequest)
|
http.Error(w, "no body", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user