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 1442475
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,17 @@ func (h *Handler) isPublicShare(r *http.Request, oid string) (*link.PublicShare,
},
},
})
if err != nil {
logger.Err(err)
return nil, false
}

return psRes.GetShare(), psRes.GetShare() != nil
switch {
case err != nil:
log.Err(err).Send()
case psRes.Status.Code == rpc.Code_CODE_OK:
return psRes.GetShare(), psRes.GetShare() != nil
case psRes.Status.Code == rpc.Code_CODE_INTERNAL:
log.Error().Str("message", psRes.GetStatus().GetMessage()).Str("code", psRes.GetStatus().GetCode().String()).Msg("isPublicShare received internal error")
default:
log.Debug().Str("message", psRes.GetStatus().GetMessage()).Str("code", psRes.GetStatus().GetCode().String()).Msg("isPublicShare received unexpected status")
}
return nil, false
}

func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, share *link.PublicShare) {
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,12 +147,17 @@ func (h *Handler) isUserShare(r *http.Request, oid string) (*collaboration.Share
},
},
})
if err != nil {
logger.Err(err)
return nil, false
switch {
case err != nil:
log.Err(err).Send()
case getShareRes.Status.Code == rpc.Code_CODE_OK:
return getShareRes.GetShare(), true
case getShareRes.Status.Code == rpc.Code_CODE_INTERNAL:
log.Error().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isUserShare received internal error")
default:
log.Debug().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isUserShare received unexpected status")
}

return getShareRes.GetShare(), getShareRes.GetShare() != nil
return nil, false
}

func (h *Handler) isFederatedShare(r *http.Request, shareID string) bool {
Expand All @@ -172,12 +177,17 @@ 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:
return true
case getShareRes.Status.Code == rpc.Code_CODE_INTERNAL:
log.Error().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isFederatedShare received internal error")
default:
log.Debug().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isFederatedShare received unexpected status")
}

return getShareRes.GetShare() != nil
return false
}

func (h *Handler) removeFederatedShare(w http.ResponseWriter, r *http.Request, shareID string) {
Expand Down Expand Up @@ -247,12 +257,17 @@ 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:
return true
case getShareRes.Status.Code == rpc.Code_CODE_INTERNAL:
log.Error().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isFederatedReceivedShare received internal error")
default:
log.Debug().Str("message", getShareRes.GetStatus().GetMessage()).Str("code", getShareRes.GetStatus().GetCode().String()).Msg("isFederatedReceivedShare received unexpected status")
}

return getShareRes.GetShare() != nil
return false
}

func (h *Handler) removeUserShare(w http.ResponseWriter, r *http.Request, share *collaboration.Share) {
Expand Down

0 comments on commit 1442475

Please sign in to comment.