Skip to content

Commit

Permalink
Identify webhook result http 2xx as OK
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Paskal <[email protected]>
  • Loading branch information
maksim-paskal committed Dec 20, 2024
1 parent 53c5037 commit 92e862d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func SetHTTPClient(c *http.Client) {
client = c
}

func isResponseOK(statusCode int) bool {
return statusCode >= 200 && statusCode < 300
}

func SendWebHook(ctx context.Context, obj *template.MessageType) error {
ctx, cancel := context.WithTimeout(ctx, *config.Get().WebHookTimeout)
defer cancel()
Expand Down Expand Up @@ -85,7 +89,7 @@ func SendWebHook(ctx context.Context, obj *template.MessageType) error {

log.Infof("response status: %s", resp.Status)

if resp.StatusCode != http.StatusOK {
if !isResponseOK(resp.StatusCode) {
return errors.Wrap(errHTTPNotOK, fmt.Sprintf("StatusCode=%d", resp.StatusCode))
}

Expand Down

0 comments on commit 92e862d

Please sign in to comment.