Skip to content

Commit

Permalink
listener: Don't error w/ 500 for superfluous events
Browse files Browse the repository at this point in the history
When, for example, resubmitting a state change, the listener will error
with an internal server error, code 500. This is both a bit heavy and
misleading.

The error is now inspected similar to the current behavior for the
icinga2.Launcher in its launch method.
  • Loading branch information
oxzi authored and julianbrost committed Jul 29, 2024
1 parent 8102c77 commit 85cc053
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/subtle"
"encoding/json"
"errors"
"fmt"
"github.com/icinga/icinga-go-library/database"
"github.com/icinga/icinga-go-library/logging"
Expand Down Expand Up @@ -133,7 +134,10 @@ func (l *Listener) ProcessEvent(w http.ResponseWriter, req *http.Request) {

l.logger.Infow("Processing event", zap.String("event", ev.String()))
err = incident.ProcessEvent(context.Background(), l.db, l.logs, l.runtimeConfig, &ev)
if err != nil {
if errors.Is(err, event.ErrSuperfluousStateChange) || errors.Is(err, event.ErrSuperfluousMuteUnmuteEvent) {
abort(http.StatusNotAcceptable, &ev, "%v", err)
return
} else if err != nil {
l.logger.Errorw("Failed to successfully process event", zap.Stringer("event", &ev), zap.Error(err))
abort(http.StatusInternalServerError, &ev, "event could not be processed successfully, see server logs for details")
return
Expand Down

0 comments on commit 85cc053

Please sign in to comment.