From 2854ea1d150bcf1025e49d6c9655186cda2a3d38 Mon Sep 17 00:00:00 2001 From: AleksandrMatsko Date: Tue, 24 Sep 2024 11:46:49 +0700 Subject: [PATCH] refactor: 4xx code recognition --- api/handler/triggers.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/handler/triggers.go b/api/handler/triggers.go index 1cf70fdba..7a4f20443 100644 --- a/api/handler/triggers.go +++ b/api/handler/triggers.go @@ -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. @@ -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 { return api.ErrorInvalidRequest(promErr) }