all 2xx status codes to be success for audit (#20394)

This commit is contained in:
Harshavardhana
2024-09-06 15:53:34 -07:00
committed by GitHub
parent 64e803b136
commit 0f1e8db4c5
3 changed files with 11 additions and 11 deletions

View File

@@ -196,13 +196,15 @@ func (target *WebhookTarget) send(eventData event.Event) error {
if err != nil {
return err
}
defer xhttp.DrainBody(resp.Body)
xhttp.DrainBody(resp.Body)
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("sending event failed with %v", resp.Status)
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
// accepted HTTP status codes.
return nil
} else if resp.StatusCode == http.StatusForbidden {
return fmt.Errorf("%s returned '%s', please check if your auth token is correctly set", target.args.Endpoint, resp.Status)
}
return nil
return fmt.Errorf("%s returned '%s', please check your endpoint configuration", target.args.Endpoint, resp.Status)
}
// SendFromStore - reads an event from store and sends it to webhook.