From 3b9629e294f9eda05d6afb259f8c981d3791a68c Mon Sep 17 00:00:00 2001 From: Paul Gier Date: Fri, 29 Mar 2019 10:02:39 -0500 Subject: [PATCH] cli: check for NotFound error during silence import Check the error type when there is a non-existent silence instead of comparing the text of the error message. Signed-off-by: Paul Gier --- cli/silence_import.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/silence_import.go b/cli/silence_import.go index 8bb45466..1e024d51 100644 --- a/cli/silence_import.go +++ b/cli/silence_import.go @@ -18,7 +18,6 @@ import ( "encoding/json" "fmt" "os" - "strings" "sync" "github.com/pkg/errors" @@ -63,7 +62,7 @@ func addSilenceWorker(ctx context.Context, sclient *silence.Client, silencec <-c sid := s.ID params := silence.NewPostSilencesParams().WithContext(ctx).WithSilence(s) postOk, err := sclient.PostSilences(params) - if err != nil && strings.Contains(err.Error(), "not found") { + if _, ok := err.(*silence.PostSilencesNotFound); ok { // silence doesn't exists yet, retry to create as a new one params.Silence.ID = "" postOk, err = sclient.PostSilences(params)