Skip to content

Commit

Permalink
When trying to renew an expired subscription, create new subscription…
Browse files Browse the repository at this point in the history
… instead (#131)

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
  • Loading branch information
mickmister and hanzei authored Nov 19, 2020
1 parent b8de849 commit 50beb11
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/mscalendar/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package mscalendar

import (
"strings"

"github.com/pkg/errors"

"github.com/mattermost/mattermost-plugin-mscalendar/server/config"
Expand Down Expand Up @@ -81,6 +83,15 @@ func (m *mscalendar) RenewMyEventSubscription() (*store.Subscription, error) {
}
renewed, err := m.client.RenewSubscription(subscriptionID)
if err != nil {
if strings.Contains(err.Error(), "The object was not found") {
err = m.Store.DeleteUserSubscription(m.actingUser.User, subscriptionID)
if err != nil {
return nil, err
}

m.Logger.Infof("Subscription %s for Mattermost user %s has expired. Creating a new subscription now.", subscriptionID, m.actingUser.MattermostUserID)
return m.CreateMyEventSubscription()
}
return nil, err
}

Expand Down

0 comments on commit 50beb11

Please sign in to comment.