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 {
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
}
defer resp.Body.Close()

View file

@ -16,4 +16,6 @@ func (se ServerError) Error() string {
var (
// ErrOauthRevoked .
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...)
if err != nil {
if err != reddit.ErrOauthRevoked {
nc.logger.WithFields(logrus.Fields{
"account#username": account.NormalizedUsername(),
"err": err,
}).Error("failed to fetch message inbox")
return
}
switch err {
case reddit.ErrTimeout: // Don't log timeouts
break
case reddit.ErrOauthRevoked:
err = nc.deleteAccount(ctx, account)
if err != nil {
nc.logger.WithFields(logrus.Fields{
@ -262,6 +258,13 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
nc.logger.WithFields(logrus.Fields{
"account#username": account.NormalizedUsername(),
}).Info("removed revoked account")
break
default:
nc.logger.WithFields(logrus.Fields{
"account#username": account.NormalizedUsername(),
"err": err,
}).Error("failed to fetch message inbox")
}
return
}