From 50beb111d6e603a5181691d2b923586de942fbf7 Mon Sep 17 00:00:00 2001 From: Michael Kochell <6913320+mickmister@users.noreply.github.com> Date: Wed, 18 Nov 2020 21:42:40 -0500 Subject: [PATCH] When trying to renew an expired subscription, create new subscription instead (#131) Co-authored-by: Ben Schumacher --- server/mscalendar/subscription.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/mscalendar/subscription.go b/server/mscalendar/subscription.go index 1dce3c8c..98115d86 100644 --- a/server/mscalendar/subscription.go +++ b/server/mscalendar/subscription.go @@ -4,6 +4,8 @@ package mscalendar import ( + "strings" + "github.com/pkg/errors" "github.com/mattermost/mattermost-plugin-mscalendar/server/config" @@ -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 }