diff --git a/pkg/authorization/middleware.go b/pkg/authorization/middleware.go index 1adc660c5b..52890dd360 100644 --- a/pkg/authorization/middleware.go +++ b/pkg/authorization/middleware.go @@ -64,15 +64,21 @@ func (m *Middleware) WrapHandler(handler func(ctx context.Context, w http.Respon rw := NewResponseModifier(w) - if err := handler(ctx, rw, r, vars); err != nil { - logrus.Errorf("Handler for %s %s returned error: %s", r.Method, r.RequestURI, err) - return err + var errD error + + if errD = handler(ctx, rw, r, vars); errD != nil { + logrus.Errorf("Handler for %s %s returned error: %s", r.Method, r.RequestURI, errD) } - if err := authCtx.AuthZResponse(rw, r); err != nil { + if err := authCtx.AuthZResponse(rw, r); errD == nil && err != nil { logrus.Errorf("AuthZResponse for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } + + if errD != nil { + return errD + } + return nil } }