Skip to content

Commit

Permalink
add logging on unexpected status codes
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Aug 2, 2024
1 parent 6562481 commit 84a2ef9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 84a2ef9

Please sign in to comment.