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 <pgier@redhat.com>
This commit is contained in:
Paul Gier 2019-03-29 10:02:39 -05:00
parent 52f78c5b88
commit 3b9629e294

View File

@ -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)