From 842252f9e26705891602d86639773341332aa1c8 Mon Sep 17 00:00:00 2001 From: Vikram Rangnekar Date: Sun, 3 May 2020 20:52:26 -0400 Subject: [PATCH] fix: fix issue with skipping prepared statements for some roles on error --- core/prepare.go | 2 +- internal/serv/http.go | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/core/prepare.go b/core/prepare.go index 44f0694..6635e8a 100644 --- a/core/prepare.go +++ b/core/prepare.go @@ -122,7 +122,7 @@ func (sg *SuperGraph) prepareStmt(item allow.Item) error { stmts, err := sg.buildRoleStmt(qb, vars, role.Name) if err == psql.ErrAllTablesSkipped { - return nil + continue } if err != nil { return err diff --git a/internal/serv/http.go b/internal/serv/http.go index 62651ea..eb7d699 100644 --- a/internal/serv/http.go +++ b/internal/serv/http.go @@ -92,17 +92,28 @@ func apiV1(w http.ResponseWriter, r *http.Request) { //nolint: errcheck json.NewEncoder(w).Encode(res) + if doLog && logLevel >= LogLevelInfo { + zlog.Info("success", + zap.String("op", res.OperationName()), + zap.String("name", res.QueryName()), + zap.String("role", res.Role()), + ) + } + } else { renderErr(w, err) + + if doLog && logLevel >= LogLevelInfo { + zlog.Error("error", + zap.String("op", res.OperationName()), + zap.String("name", res.QueryName()), + zap.String("role", res.Role()), + zap.Error(err), + ) + } + } - if doLog && logLevel >= LogLevelInfo { - zlog.Info("success", - zap.String("op", res.OperationName()), - zap.String("name", res.QueryName()), - zap.String("role", res.Role()), - ) - } } //nolint: errcheck