root: fix linting errors
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
@ -5,10 +5,12 @@ import (
|
||||
"net/http"
|
||||
|
||||
sentryhttp "github.com/getsentry/sentry-go/http"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func recoveryMiddleware() func(next http.Handler) http.Handler {
|
||||
sentryHandler := sentryhttp.New(sentryhttp.Options{})
|
||||
l := log.WithField("logger", "authentik.sentry")
|
||||
return func(next http.Handler) http.Handler {
|
||||
sentryHandler.Handle(next)
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@ -20,6 +22,7 @@ func recoveryMiddleware() func(next http.Handler) http.Handler {
|
||||
}
|
||||
err := re.(error)
|
||||
if err != nil {
|
||||
l.WithError(err).Warning("global panic handler")
|
||||
jsonBody, _ := json.Marshal(struct {
|
||||
Successful bool
|
||||
Error string
|
||||
@ -30,7 +33,10 @@ func recoveryMiddleware() func(next http.Handler) http.Handler {
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write(jsonBody)
|
||||
_, err := w.Write(jsonBody)
|
||||
if err != nil {
|
||||
l.WithError(err).Warning("Failed to write sentry error body")
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
@ -66,7 +66,10 @@ func (ws *WebServer) listenPlain() {
|
||||
ws.serve(ln)
|
||||
|
||||
ws.log.WithField("addr", config.G.Web.Listen).Info("Running")
|
||||
http.ListenAndServe(config.G.Web.Listen, ws.m)
|
||||
err = http.ListenAndServe(config.G.Web.Listen, ws.m)
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
ws.log.Errorf("ERROR: http.Serve() - %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ws *WebServer) serve(listener net.Listener) {
|
||||
|
||||
@ -23,6 +23,7 @@ func (ws *WebServer) listenTLS() {
|
||||
ln, err := net.Listen("tcp", config.G.Web.ListenTLS)
|
||||
if err != nil {
|
||||
ws.log.WithError(err).Fatalf("failed to listen")
|
||||
return
|
||||
}
|
||||
ws.log.WithField("addr", config.G.Web.ListenTLS).Info("Running")
|
||||
|
||||
|
||||
@ -29,12 +29,18 @@ func (ws *WebServer) configureStatic() {
|
||||
ws.lh.Path("/robots.txt").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.Header()["Content-Type"] = []string{"text/plain"}
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(staticWeb.RobotsTxt)
|
||||
_, err := rw.Write(staticWeb.RobotsTxt)
|
||||
if err != nil {
|
||||
ws.log.WithError(err).Warning("failed to write response")
|
||||
}
|
||||
})
|
||||
ws.lh.Path("/.well-known/security.txt").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.Header()["Content-Type"] = []string{"text/plain"}
|
||||
rw.WriteHeader(200)
|
||||
rw.Write(staticWeb.SecurityTxt)
|
||||
_, err := rw.Write(staticWeb.SecurityTxt)
|
||||
if err != nil {
|
||||
ws.log.WithError(err).Warning("failed to write response")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user