Refactor errorResponse to set the logger to debug if the response cod… (#2719)

* Refactor errorResponse to set the logger to debug if the response code is set to unauthorised. Fixes #2488

* Fix merge conflicts
This commit is contained in:
João Aldeano 2022-04-06 12:54:40 +01:00 committed by GitHub
parent 2c067147e7
commit 263bd92424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3873,12 +3873,21 @@ func (a *API) handleDeleteBoardsAndBlocks(w http.ResponseWriter, r *http.Request
// Response helpers // Response helpers
func (a *API) errorResponse(w http.ResponseWriter, api string, code int, message string, sourceError error) { func (a *API) errorResponse(w http.ResponseWriter, api string, code int, message string, sourceError error) {
a.logger.Error("API ERROR", if code == http.StatusUnauthorized {
mlog.Int("code", code), a.logger.Debug("API DEBUG",
mlog.Err(sourceError), mlog.Int("code", code),
mlog.String("msg", message), mlog.Err(sourceError),
mlog.String("api", api), mlog.String("msg", message),
) mlog.String("api", api),
)
} else {
a.logger.Error("API ERROR",
mlog.Int("code", code),
mlog.Err(sourceError),
mlog.String("msg", message),
mlog.String("api", api),
)
}
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
data, err := json.Marshal(model.ErrorResponse{Error: message, ErrorCode: code}) data, err := json.Marshal(model.ErrorResponse{Error: message, ErrorCode: code})