diff --git a/.golangci.yml b/.golangci.yml index df7f259..f74fa4e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,6 @@ linters: - errname # checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error` - exportloopref # checks for pointers to enclosing loop variables - gochecknoinits # checks that no init functions are present in Go code - - ifshort # checks that your code uses short syntax for if-statements whenever possible - importas # enforces consistent import aliases - ineffassign # detects when assignments to existing variables are not used - noctx # finds sending http request without context.Context diff --git a/internal/reddit/client.go b/internal/reddit/client.go index a2cf40c..2313c03 100644 --- a/internal/reddit/client.go +++ b/internal/reddit/client.go @@ -56,6 +56,7 @@ var ( defaultErrorMap = map[int]error{ 401: ErrOauthRevoked, 403: ErrOauthRevoked, + 404: ErrSubredditNotFound, } ) diff --git a/internal/worker/subreddits.go b/internal/worker/subreddits.go index 8ee0113..1bb9c95 100644 --- a/internal/worker/subreddits.go +++ b/internal/worker/subreddits.go @@ -219,13 +219,22 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) { zap.Int("page", page), ) - if err == reddit.ErrOauthRevoked { + switch err { + case reddit.ErrOauthRevoked: sc.logger.Info("deleting watcher", zap.Int64("subreddit#id", id), zap.String("subreddit#name", subreddit.NormalizedName()), zap.Int64("watcher#id", watcher.ID), ) _ = sc.watcherRepo.Delete(ctx, watcher.ID) + case reddit.ErrSubredditNotFound: + sc.logger.Info("subreddit deleted, deleting watchers", + zap.Int64("subreddit#id", id), + zap.String("subreddit#name", subreddit.NormalizedName()), + ) + for _, watcher := range watchers { + _ = sc.watcherRepo.Delete(ctx, watcher.ID) + } } return @@ -447,7 +456,7 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) { ) } else if !res.Sent() { _ = sc.statsd.Incr("apns.notification.errors", []string{}, 1) - sc.logger.Error("notificaion not sent", + sc.logger.Error("notification not sent", zap.Int64("subreddit#id", id), zap.String("subreddit#name", subreddit.NormalizedName()), zap.String("post#id", post.ID),