Skip to content

Commit

Permalink
[CCXDEV-14053] Don't use ERROR level for all kind of HTTP error respo…
Browse files Browse the repository at this point in the history
…nses (#568)

* don't use ERROR level for all kind of HTTP error responses

* don't duplicate logs
  • Loading branch information
juandspy authored Aug 6, 2024
1 parent 19b9bb2 commit af9e6e2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

// responseDataError is used as the error message when the responses functions return an error
const responseDataError = "Unexpected error during response data encoding"
const handleServerErrorStr = "handleServerError()"

// RouterMissingParamError missing parameter in request
type RouterMissingParamError struct {
Expand Down Expand Up @@ -107,7 +108,7 @@ func (e *ValidationError) Error() string {

// HandleServerError handles separate server errors and sends appropriate responses
func HandleServerError(writer http.ResponseWriter, err error) {
log.Error().Err(err).Msg("handleServerError()")
var level = log.Warn() // set the default log level for most HTTP responses

var respErr error

Expand All @@ -123,9 +124,12 @@ func HandleServerError(writer http.ResponseWriter, err error) {
case *ForbiddenError:
respErr = responses.SendForbidden(writer, err.Error())
default:
level = log.Error()
respErr = responses.SendInternalServerError(writer, "Internal Server Error")
}

level.Err(err).Msg(handleServerErrorStr)

if respErr != nil {
log.Error().Err(respErr).Msg(responseDataError)
}
Expand Down

0 comments on commit af9e6e2

Please sign in to comment.