mirror of
https://github.com/foomo/contentserver.git
synced 2025-10-16 12:25:44 +00:00
Merge pull request #19 from foomo/feature/contentserver-panic-fix
ContentServer Panic Fix
This commit is contained in:
commit
130ab553e3
2
go.mod
2
go.mod
@ -12,3 +12,5 @@ require (
|
||||
go.uber.org/multierr v1.1.0 // indirect
|
||||
go.uber.org/zap v1.10.0
|
||||
)
|
||||
|
||||
go 1.13
|
||||
|
||||
@ -184,15 +184,7 @@ func (repo *Repo) GetContent(r *requests.Content) (c *content.SiteContent, err e
|
||||
Log.Info("resolvecontent got status 404", zap.String("URI", r.URI))
|
||||
c.Status = content.StatusNotFound
|
||||
c.Dimension = r.Env.Dimensions[0]
|
||||
}
|
||||
|
||||
Log.Debug("got content",
|
||||
zap.Bool("resolved", resolved),
|
||||
zap.String("resolvedURI", resolvedURI),
|
||||
zap.String("resolvedDimension", resolvedDimension),
|
||||
zap.String("nodeName", node.Name),
|
||||
)
|
||||
if !resolved {
|
||||
Log.Debug("failed to resolve, falling back to default dimension",
|
||||
zap.String("URI", r.URI),
|
||||
zap.String("defaultDimension", r.Env.Dimensions[0]),
|
||||
@ -200,6 +192,7 @@ func (repo *Repo) GetContent(r *requests.Content) (c *content.SiteContent, err e
|
||||
// r.Env.Dimensions is validated => we can access it
|
||||
resolvedDimension = r.Env.Dimensions[0]
|
||||
}
|
||||
|
||||
// add navigation trees
|
||||
for _, node := range r.Nodes {
|
||||
if node.Dimension == "" {
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user