From 8c206c1fd4542ddd8c87125436ec3095cf0c3bf6 Mon Sep 17 00:00:00 2001 From: Mylon Suren <23694620+mylonsuren@users.noreply.github.com> Date: Thu, 8 Dec 2022 09:40:14 -0500 Subject: [PATCH] [MM-48921] Don't return error when deleting Draft if Draft DNE (#21818) * set global drafts feature flag to true * Don't return error on deleteDraft when draft doesn't exist in server * undo accidental feature flag change * address comments * change log level to debug Co-authored-by: Mattermod --- api4/drafts.go | 9 ++++++++- app/draft.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api4/drafts.go b/api4/drafts.go index 92dd6f2c58..102c164b8f 100644 --- a/api4/drafts.go +++ b/api4/drafts.go @@ -121,7 +121,14 @@ func deleteDraft(c *Context, w http.ResponseWriter, r *http.Request) { draft, err := c.App.GetDraft(userID, channelID, rootID) if err != nil { - c.Err = err + switch { + case err.StatusCode == http.StatusNotFound: + // If the draft doesn't exist in the server, we don't need to delete. + mlog.Debug("Unable to find the draft", mlog.Err(err)) + ReturnStatusOK(w) + default: + c.Err = err + } return } diff --git a/app/draft.go b/app/draft.go index 46f96d7fae..18dd2bde00 100644 --- a/app/draft.go +++ b/app/draft.go @@ -25,7 +25,7 @@ func (a *App) GetDraft(userID, channelID, rootID string) (*model.Draft, *model.A var nfErr *store.ErrNotFound switch { case errors.As(err, &nfErr): - return nil, model.NewAppError("GetDraft", "app.draft.get.app_error", nil, nfErr.Error(), http.StatusNotFound) + return nil, model.NewAppError("GetDraft", "app.draft.get.app_error", nil, err.Error(), http.StatusNotFound) default: return nil, model.NewAppError("GetDraft", "app.draft.get.app_error", nil, err.Error(), http.StatusInternalServerError) }