report timeout errors separately

This commit is contained in:
Andre Medeiros 2021-08-14 14:07:19 -04:00
parent 7f8d0c3375
commit 42a9fb415e
3 changed files with 22 additions and 14 deletions

View file

@ -107,6 +107,9 @@ func (rac *AuthenticatedClient) request(r *Request, rh ResponseHandler, empty in
if err != nil { if err != nil {
rac.statsd.Incr("reddit.api.errors", r.tags, 0.1) rac.statsd.Incr("reddit.api.errors", r.tags, 0.1)
if strings.Contains(err.Error(), "http2: timeout awaiting response headers") {
return nil, ErrTimeout
}
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()

View file

@ -16,4 +16,6 @@ func (se ServerError) Error() string {
var ( var (
// ErrOauthRevoked . // ErrOauthRevoked .
ErrOauthRevoked = errors.New("oauth revoked") ErrOauthRevoked = errors.New("oauth revoked")
// ErrTimeout .
ErrTimeout = errors.New("timeout")
) )

View file

@ -243,14 +243,10 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
msgs, err := rac.MessageInbox(opts...) msgs, err := rac.MessageInbox(opts...)
if err != nil { if err != nil {
if err != reddit.ErrOauthRevoked { switch err {
nc.logger.WithFields(logrus.Fields{ case reddit.ErrTimeout: // Don't log timeouts
"account#username": account.NormalizedUsername(), break
"err": err, case reddit.ErrOauthRevoked:
}).Error("failed to fetch message inbox")
return
}
err = nc.deleteAccount(ctx, account) err = nc.deleteAccount(ctx, account)
if err != nil { if err != nil {
nc.logger.WithFields(logrus.Fields{ nc.logger.WithFields(logrus.Fields{
@ -262,6 +258,13 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
nc.logger.WithFields(logrus.Fields{ nc.logger.WithFields(logrus.Fields{
"account#username": account.NormalizedUsername(), "account#username": account.NormalizedUsername(),
}).Info("removed revoked account") }).Info("removed revoked account")
break
default:
nc.logger.WithFields(logrus.Fields{
"account#username": account.NormalizedUsername(),
"err": err,
}).Error("failed to fetch message inbox")
}
return return
} }