Skip to content

Commit

Permalink
stop logging errors for api error responses (#8)
Browse files Browse the repository at this point in the history
* stop logging errors for api error responses

From a cursory glance, when a real error occurs, we already log
something at the application layer, so there's no reason to echo every
api error response as an error log too. Errors should be actionable, but
these logs were not, e.g.:

> access denied to templates

or:

> category ID specified in input does not exist for user

* Update server/api/api.go

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

---------

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>
  • Loading branch information
lieut-data and marianunez authored Jul 15, 2024
1 parent 0b6e443 commit d6a516a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ func (a *API) userIsGuest(userID string) (bool, error) {
// Response helpers

func (a *API) errorResponse(w http.ResponseWriter, r *http.Request, err error) {
a.logger.Error(err.Error())
errorResponse := model.ErrorResponse{Error: err.Error()}

switch {
Expand All @@ -195,15 +194,16 @@ func (a *API) errorResponse(w http.ResponseWriter, r *http.Request, err error) {
case model.IsErrNotImplemented(err):
errorResponse.ErrorCode = http.StatusNotImplemented
default:
a.logger.Error("API ERROR",
mlog.Int("code", http.StatusInternalServerError),
mlog.Err(err),
mlog.String("api", r.URL.Path),
)
errorResponse.Error = "internal server error"
errorResponse.ErrorCode = http.StatusInternalServerError
}

a.logger.Warn("api error response",
mlog.Int("code", errorResponse.ErrorCode),
mlog.Err(err),
mlog.String("api", r.URL.Path),
)

setResponseHeader(w, "Content-Type", "application/json")
data, err := json.Marshal(errorResponse)
if err != nil {
Expand Down

0 comments on commit d6a516a

Please sign in to comment.