MM-49546: Sentry crash: fix nil pointer dereference (#22018)

We return a store error always to be handled correctly
at the app layer.

https://mattermost.atlassian.net/browse/MM-49546

```release-note
NONE
```

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Agniva De Sarker
2023-01-09 22:25:29 +05:30
коммит произвёл GitHub
родитель d27d7bc8f7
Коммит 079f752478
2 изменённых файлов: 8 добавлений и 1 удалений

Просмотреть файл

@@ -2409,10 +2409,17 @@ func TestFollowThreadSkipsParticipants(t *testing.T) {
require.True(t, p.Id == sysadmin.Id || p.Id == user.Id)
}
oldID := threadMembership.PostId
threadMembership.PostId = "notfound"
_, err = th.App.GetThreadForUser(threadMembership, false)
require.NotNil(t, err)
assert.Equal(t, http.StatusNotFound, err.StatusCode)
threadMembership.Following = false
threadMembership.PostId = oldID
_, err = th.App.GetThreadForUser(threadMembership, false)
require.NotNil(t, err)
assert.Equal(t, http.StatusNotFound, err.StatusCode)
}
func TestAutofollowBasedOnRootPost(t *testing.T) {

Просмотреть файл

@@ -503,7 +503,7 @@ func (s *SqlThreadStore) GetThreadFollowers(threadID string, fetchOnlyActive boo
func (s *SqlThreadStore) GetThreadForUser(threadMembership *model.ThreadMembership, extended, postPriorityEnabled bool) (*model.ThreadResponse, error) {
if !threadMembership.Following {
return nil, nil // in case the thread is not followed anymore - return nil error to be interpreted as 404
return nil, store.NewErrNotFound("ThreadMembership", "<following>")
}
unreadRepliesQuery := sq.