Skip to content

Commit

Permalink
refactor: 4xx code recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrMatsko committed Sep 24, 2024
1 parent 6808ccf commit 2854ea1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/handler/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func createTrigger(writer http.ResponseWriter, request *http.Request) {
}
}

func is4xxCode(statusCode int) bool {
return statusCode >= 400 && statusCode < 500
}

func errorResponseOnPrometheusError(promErr *prometheus.Error) *api.ErrorResponse {
// In github.com/prometheus/client_golang/api/prometheus/v1 Error has field `Type`
// which can be used to understand "the reason" of error. There are some constants in the lib.
Expand All @@ -171,7 +175,7 @@ func errorResponseOnPrometheusError(promErr *prometheus.Error) *api.ErrorRespons
http.StatusForbidden: {},
}

if _, leadTo500 := codes4xxLeadTo500[statusCode]; statusCode/100 == 4 && !leadTo500 {
if _, leadTo500 := codes4xxLeadTo500[statusCode]; is4xxCode(int(statusCode)) && !leadTo500 {

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
to a lower bit size type int without an upper bound check.
return api.ErrorInvalidRequest(promErr)
}

Expand Down

0 comments on commit 2854ea1

Please sign in to comment.