feat: global error handler with template rendering
Some checks are pending
Cadoles/bouncer/pipeline/pr-develop Build started...

This commit is contained in:
2024-09-27 10:09:25 +02:00
parent 590505e17a
commit d4c28b80d7
11 changed files with 109 additions and 63 deletions

View File

@ -11,7 +11,6 @@ import (
ruleHTTP "forge.cadoles.com/cadoles/bouncer/internal/rule/http"
"forge.cadoles.com/cadoles/bouncer/internal/store"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
)
const LayerType store.LayerType = "rewriter"
@ -32,9 +31,7 @@ func (l *Layer) Middleware(layer *store.Layer) proxy.Middleware {
options, err := fromStoreOptions(layer.Options)
if err != nil {
logger.Error(ctx, "could not parse layer options", logger.CapturedE(errors.WithStack(err)))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
director.HandleError(ctx, w, r, http.StatusInternalServerError, errors.New("could not parse layer options"))
return
}
@ -52,8 +49,7 @@ func (l *Layer) Middleware(layer *store.Layer) proxy.Middleware {
return
}
logger.Error(ctx, "could not apply request rules", logger.CapturedE(errors.WithStack(err)))
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
director.HandleError(ctx, w, r, http.StatusInternalServerError, errors.Wrap(err, "could not apply request rules"))
return
}