From 84a2ef9a0b0be4dd606a9427ee9629022ec31c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 23 Apr 2024 13:21:12 +0200 Subject: [PATCH] add logging on unexpected status codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../handlers/apps/sharing/shares/public.go | 9 +++++-- .../ocs/handlers/apps/sharing/shares/user.go | 27 ++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go index dd636f4b54..7d9840ecde 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go @@ -295,9 +295,14 @@ func (h *Handler) isPublicShare(r *http.Request, oid string) (*link.PublicShare, }, }, }) - if err != nil { - logger.Err(err) + switch { + case err != nil: + log.Err(err).Send() return nil, false + case psRes.Status.Code == rpc.Code_CODE_OK: + fallthrough + case psRes.Status.Code == rpc.Code_CODE_NOT_FOUND: + log.Debug().Str("message", psRes.GetStatus().GetMessage()).Str("code", psRes.GetStatus().GetCode().String()).Msg("isPublicShare received unexpected status") } return psRes.GetShare(), psRes.GetShare() != nil diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go index 65247a9443..f47e1d5115 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go @@ -132,10 +132,10 @@ func (h *Handler) createUserShare(w http.ResponseWriter, r *http.Request, statIn } func (h *Handler) isUserShare(r *http.Request, oid string) (*collaboration.Share, bool) { - logger := appctx.GetLogger(r.Context()) + log := appctx.GetLogger(r.Context()) client, err := pool.GetGatewayServiceClient(h.gatewayAddr) if err != nil { - logger.Err(err) + log.Err(err).Send() } getShareRes, err := client.GetShare(r.Context(), &collaboration.GetShareRequest{ @@ -147,9 +147,14 @@ func (h *Handler) isUserShare(r *http.Request, oid string) (*collaboration.Share }, }, }) - if err != nil { - logger.Err(err) + switch { + case err != nil: + log.Err(err).Send() return nil, false + case getShareRes.Status.Code == rpc.Code_CODE_OK: + fallthrough + case getShareRes.Status.Code == rpc.Code_CODE_NOT_FOUND: + log.Debug().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isUserShare received unexpected status") } return getShareRes.GetShare(), getShareRes.GetShare() != nil @@ -172,9 +177,14 @@ func (h *Handler) isFederatedShare(r *http.Request, shareID string) bool { }, }, }) - if err != nil { + switch { + case err != nil: log.Err(err).Send() return false + case getShareRes.Status.Code == rpc.Code_CODE_OK: + fallthrough + case getShareRes.Status.Code == rpc.Code_CODE_NOT_FOUND: + log.Debug().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isFederatedShare received unexpected status") } return getShareRes.GetShare() != nil @@ -247,9 +257,14 @@ func (h *Handler) isFederatedReceivedShare(r *http.Request, shareID string) bool }, }, }) - if err != nil { + switch { + case err != nil: log.Err(err).Send() return false + case getShareRes.Status.Code == rpc.Code_CODE_OK: + fallthrough + case getShareRes.Status.Code == rpc.Code_CODE_NOT_FOUND: + log.Debug().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isFederatedReceivedShare received unexpected status") } return getShareRes.GetShare() != nil