diff options
author | George Goldberg <george@gberg.me> | 2017-09-19 10:24:52 +0100 |
---|---|---|
committer | Saturnino Abril <saturnino.abril@gmail.com> | 2017-09-19 17:24:52 +0800 |
commit | 3811b1ce1e9cc0aab19ee09200f755c9defbfdc7 (patch) | |
tree | 2b91d97327caf7301d6e058800d154f310808b7f /store | |
parent | 99530152643aa390fabd4d887645f72f0af68e0d (diff) | |
download | chat-3811b1ce1e9cc0aab19ee09200f755c9defbfdc7.tar.gz chat-3811b1ce1e9cc0aab19ee09200f755c9defbfdc7.tar.bz2 chat-3811b1ce1e9cc0aab19ee09200f755c9defbfdc7.zip |
Add error codes to oauth/post/preference store errors. (#7460)
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_oauth_store.go | 54 | ||||
-rw-r--r-- | store/sql_post_store.go | 55 | ||||
-rw-r--r-- | store/sql_preference_store.go | 44 |
3 files changed, 76 insertions, 77 deletions
diff --git a/store/sql_oauth_store.go b/store/sql_oauth_store.go index 0a5f14dc4..77cee7cf2 100644 --- a/store/sql_oauth_store.go +++ b/store/sql_oauth_store.go @@ -67,7 +67,7 @@ func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) StoreChannel { result := StoreResult{} if len(app.Id) > 0 { - result.Err = model.NewLocAppError("SqlOAuthStore.SaveApp", "store.sql_oauth.save_app.existing.app_error", nil, "app_id="+app.Id) + result.Err = model.NewAppError("SqlOAuthStore.SaveApp", "store.sql_oauth.save_app.existing.app_error", nil, "app_id="+app.Id, http.StatusBadRequest) storeChannel <- result close(storeChannel) return @@ -81,7 +81,7 @@ func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) StoreChannel { } if err := as.GetMaster().Insert(app); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.SaveApp", "store.sql_oauth.save_app.save.app_error", nil, "app_id="+app.Id+", "+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.SaveApp", "store.sql_oauth.save_app.save.app_error", nil, "app_id="+app.Id+", "+err.Error(), http.StatusInternalServerError) } else { result.Data = app } @@ -109,18 +109,18 @@ func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) StoreChannel { } if oldAppResult, err := as.GetMaster().Get(model.OAuthApp{}, app.Id); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.finding.app_error", nil, "app_id="+app.Id+", "+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.finding.app_error", nil, "app_id="+app.Id+", "+err.Error(), http.StatusInternalServerError) } else if oldAppResult == nil { - result.Err = model.NewLocAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.find.app_error", nil, "app_id="+app.Id) + result.Err = model.NewAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.find.app_error", nil, "app_id="+app.Id, http.StatusBadRequest) } else { oldApp := oldAppResult.(*model.OAuthApp) app.CreateAt = oldApp.CreateAt app.CreatorId = oldApp.CreatorId if count, err := as.GetMaster().Update(app); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.updating.app_error", nil, "app_id="+app.Id+", "+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.updating.app_error", nil, "app_id="+app.Id+", "+err.Error(), http.StatusInternalServerError) } else if count != 1 { - result.Err = model.NewLocAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.update.app_error", nil, "app_id="+app.Id) + result.Err = model.NewAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.update.app_error", nil, "app_id="+app.Id, http.StatusBadRequest) } else { result.Data = [2]*model.OAuthApp{app, oldApp} } @@ -232,7 +232,7 @@ func (as SqlOAuthStore) DeleteApp(id string) StoreChannel { // wrap in a transaction so that if one fails, everything fails transaction, err := as.GetMaster().Begin() if err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete.open_transaction.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) } else { if extrasResult := as.deleteApp(transaction, id); extrasResult.Err != nil { result = extrasResult @@ -241,11 +241,11 @@ func (as SqlOAuthStore) DeleteApp(id string) StoreChannel { if result.Err == nil { if err := transaction.Commit(); err != nil { // don't need to rollback here since the transaction is already closed - result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete.commit_transaction.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) } } else { if err := transaction.Rollback(); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete.rollback_transaction.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete.rollback_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) } } } @@ -271,7 +271,7 @@ func (as SqlOAuthStore) SaveAccessData(accessData *model.AccessData) StoreChanne } if err := as.GetMaster().Insert(accessData); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.SaveAccessData", "store.sql_oauth.save_access_data.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.SaveAccessData", "store.sql_oauth.save_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = accessData } @@ -293,7 +293,7 @@ func (as SqlOAuthStore) GetAccessData(token string) StoreChannel { accessData := model.AccessData{} if err := as.GetReplica().SelectOne(&accessData, "SELECT * FROM OAuthAccessData WHERE Token = :Token", map[string]interface{}{"Token": token}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.GetAccessData", "store.sql_oauth.get_access_data.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.GetAccessData", "store.sql_oauth.get_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = &accessData } @@ -318,9 +318,7 @@ func (as SqlOAuthStore) GetAccessDataByUserForApp(userId, clientId string) Store if _, err := as.GetReplica().Select(&accessData, "SELECT * FROM OAuthAccessData WHERE UserId = :UserId AND ClientId = :ClientId", map[string]interface{}{"UserId": userId, "ClientId": clientId}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.GetAccessDataByUserForApp", - "store.sql_oauth.get_access_data_by_user_for_app.app_error", nil, - "user_id="+userId+" client_id="+clientId) + result.Err = model.NewAppError("SqlOAuthStore.GetAccessDataByUserForApp", "store.sql_oauth.get_access_data_by_user_for_app.app_error", nil, "user_id="+userId+" client_id="+clientId, http.StatusInternalServerError) } else { result.Data = accessData } @@ -343,7 +341,7 @@ func (as SqlOAuthStore) GetAccessDataByRefreshToken(token string) StoreChannel { accessData := model.AccessData{} if err := as.GetReplica().SelectOne(&accessData, "SELECT * FROM OAuthAccessData WHERE RefreshToken = :Token", map[string]interface{}{"Token": token}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.GetAccessData", "store.sql_oauth.get_access_data.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.GetAccessData", "store.sql_oauth.get_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = &accessData } @@ -370,7 +368,7 @@ func (as SqlOAuthStore) GetPreviousAccessData(userId, clientId string) StoreChan if strings.Contains(err.Error(), "no rows") { result.Data = nil } else { - result.Err = model.NewLocAppError("SqlOAuthStore.GetPreviousAccessData", "store.sql_oauth.get_previous_access_data.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.GetPreviousAccessData", "store.sql_oauth.get_previous_access_data.app_error", nil, err.Error(), http.StatusNotFound) } } else { result.Data = &accessData @@ -398,8 +396,8 @@ func (as SqlOAuthStore) UpdateAccessData(accessData *model.AccessData) StoreChan if _, err := as.GetMaster().Exec("UPDATE OAuthAccessData SET Token = :Token, ExpiresAt = :ExpiresAt, RefreshToken = :RefreshToken WHERE ClientId = :ClientId AND UserID = :UserId", map[string]interface{}{"Token": accessData.Token, "ExpiresAt": accessData.ExpiresAt, "RefreshToken": accessData.RefreshToken, "ClientId": accessData.ClientId, "UserId": accessData.UserId}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.Update", "store.sql_oauth.update_access_data.app_error", nil, - "clientId="+accessData.ClientId+",userId="+accessData.UserId+", "+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.Update", "store.sql_oauth.update_access_data.app_error", nil, + "clientId="+accessData.ClientId+",userId="+accessData.UserId+", "+err.Error(), http.StatusInternalServerError) } else { result.Data = accessData } @@ -418,7 +416,7 @@ func (as SqlOAuthStore) RemoveAccessData(token string) StoreChannel { result := StoreResult{} if _, err := as.GetMaster().Exec("DELETE FROM OAuthAccessData WHERE Token = :Token", map[string]interface{}{"Token": token}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.RemoveAccessData", "store.sql_oauth.remove_access_data.app_error", nil, "err="+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.RemoveAccessData", "store.sql_oauth.remove_access_data.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -443,7 +441,7 @@ func (as SqlOAuthStore) SaveAuthData(authData *model.AuthData) StoreChannel { } if err := as.GetMaster().Insert(authData); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.SaveAuthData", "store.sql_oauth.save_auth_data.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.SaveAuthData", "store.sql_oauth.save_auth_data.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = authData } @@ -463,9 +461,9 @@ func (as SqlOAuthStore) GetAuthData(code string) StoreChannel { result := StoreResult{} if obj, err := as.GetReplica().Get(model.AuthData{}, code); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.GetAuthData", "store.sql_oauth.get_auth_data.finding.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.GetAuthData", "store.sql_oauth.get_auth_data.finding.app_error", nil, err.Error(), http.StatusInternalServerError) } else if obj == nil { - result.Err = model.NewLocAppError("SqlOAuthStore.GetAuthData", "store.sql_oauth.get_auth_data.find.app_error", nil, "") + result.Err = model.NewAppError("SqlOAuthStore.GetAuthData", "store.sql_oauth.get_auth_data.find.app_error", nil, "", http.StatusNotFound) } else { result.Data = obj.(*model.AuthData) } @@ -486,7 +484,7 @@ func (as SqlOAuthStore) RemoveAuthData(code string) StoreChannel { _, err := as.GetMaster().Exec("DELETE FROM OAuthAuthData WHERE Code = :Code", map[string]interface{}{"Code": code}) if err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.RemoveAuthData", "store.sql_oauth.remove_auth_data.app_error", nil, "err="+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.RemoveAuthData", "store.sql_oauth.remove_auth_data.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -504,7 +502,7 @@ func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(userId string) StoreChanne _, err := as.GetMaster().Exec("DELETE FROM OAuthAccessData WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}) if err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.RemoveAuthDataByUserId", "store.sql_oauth.permanent_delete_auth_data_by_user.app_error", nil, "err="+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.RemoveAuthDataByUserId", "store.sql_oauth.permanent_delete_auth_data_by_user.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -518,7 +516,7 @@ func (as SqlOAuthStore) deleteApp(transaction *gorp.Transaction, clientId string result := StoreResult{} if _, err := transaction.Exec("DELETE FROM OAuthApps WHERE Id = :Id", map[string]interface{}{"Id": clientId}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error(), http.StatusInternalServerError) return result } @@ -536,7 +534,7 @@ func (as SqlOAuthStore) deleteOAuthAppSessions(transaction *gorp.Transaction, cl } if _, err := transaction.Exec(query, map[string]interface{}{"Id": clientId}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error(), http.StatusInternalServerError) return result } @@ -547,7 +545,7 @@ func (as SqlOAuthStore) deleteOAuthTokens(transaction *gorp.Transaction, clientI result := StoreResult{} if _, err := transaction.Exec("DELETE FROM OAuthAccessData WHERE ClientId = :Id", map[string]interface{}{"Id": clientId}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error(), http.StatusInternalServerError) return result } @@ -563,7 +561,7 @@ func (as SqlOAuthStore) deleteAppExtras(transaction *gorp.Transaction, clientId WHERE Category = :Category AND Name = :Name`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, "Name": clientId}); err != nil { - result.Err = model.NewLocAppError("SqlOAuthStore.DeleteApp", "store.sql_preference.delete.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) return result } diff --git a/store/sql_post_store.go b/store/sql_post_store.go index b300f9a59..a7d47f4a9 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -82,8 +82,7 @@ func (s SqlPostStore) Save(post *model.Post) StoreChannel { result := StoreResult{} if len(post.Id) > 0 { - result.Err = model.NewLocAppError("SqlPostStore.Save", - "store.sql_post.save.existing.app_error", nil, "id="+post.Id) + result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.save.existing.app_error", nil, "id="+post.Id, http.StatusBadRequest) storeChannel <- result close(storeChannel) return @@ -97,7 +96,7 @@ func (s SqlPostStore) Save(post *model.Post) StoreChannel { } if err := s.GetMaster().Insert(post); err != nil { - result.Err = model.NewLocAppError("SqlPostStore.Save", "store.sql_post.save.app_error", nil, "id="+post.Id+", "+err.Error()) + result.Err = model.NewAppError("SqlPostStore.Save", "store.sql_post.save.app_error", nil, "id="+post.Id+", "+err.Error(), http.StatusInternalServerError) } else { time := post.UpdateAt @@ -143,7 +142,7 @@ func (s SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) StoreChan } if _, err := s.GetMaster().Update(newPost); err != nil { - result.Err = model.NewLocAppError("SqlPostStore.Update", "store.sql_post.update.app_error", nil, "id="+newPost.Id+", "+err.Error()) + result.Err = model.NewAppError("SqlPostStore.Update", "store.sql_post.update.app_error", nil, "id="+newPost.Id+", "+err.Error(), http.StatusInternalServerError) } else { time := model.GetMillis() s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": newPost.ChannelId}) @@ -180,7 +179,7 @@ func (s SqlPostStore) Overwrite(post *model.Post) StoreChannel { } if _, err := s.GetMaster().Update(post); err != nil { - result.Err = model.NewLocAppError("SqlPostStore.Overwrite", "store.sql_post.overwrite.app_error", nil, "id="+post.Id+", "+err.Error()) + result.Err = model.NewAppError("SqlPostStore.Overwrite", "store.sql_post.overwrite.app_error", nil, "id="+post.Id+", "+err.Error(), http.StatusInternalServerError) } else { result.Data = post } @@ -200,7 +199,7 @@ func (s SqlPostStore) GetFlaggedPosts(userId string, offset int, limit int) Stor var posts []*model.Post if _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE Id IN (SELECT Name FROM Preferences WHERE UserId = :UserId AND Category = :Category) AND DeleteAt = 0 ORDER BY CreateAt DESC LIMIT :Limit OFFSET :Offset", map[string]interface{}{"UserId": userId, "Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Offset": offset, "Limit": limit}); err != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetFlaggedPosts", "store.sql_post.get_flagged_posts.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPostStore.GetFlaggedPosts", "store.sql_post.get_flagged_posts.app_error", nil, err.Error(), http.StatusInternalServerError) } else { for _, post := range posts { pl.AddPost(post) @@ -252,7 +251,7 @@ func (s SqlPostStore) GetFlaggedPostsForTeam(userId, teamId string, offset int, LIMIT :Limit OFFSET :Offset` if _, err := s.GetReplica().Select(&posts, query, map[string]interface{}{"UserId": userId, "Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Offset": offset, "Limit": limit, "TeamId": teamId}); err != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetFlaggedPostsForTeam", "store.sql_post.get_flagged_posts.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPostStore.GetFlaggedPostsForTeam", "store.sql_post.get_flagged_posts.app_error", nil, err.Error(), http.StatusInternalServerError) } else { for _, post := range posts { pl.AddPost(post) @@ -288,7 +287,7 @@ func (s SqlPostStore) GetFlaggedPostsForChannel(userId, channelId string, offset LIMIT :Limit OFFSET :Offset` if _, err := s.GetReplica().Select(&posts, query, map[string]interface{}{"UserId": userId, "Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetFlaggedPostsForChannel", "store.sql_post.get_flagged_posts.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPostStore.GetFlaggedPostsForChannel", "store.sql_post.get_flagged_posts.app_error", nil, err.Error(), http.StatusInternalServerError) } else { for _, post := range posts { pl.AddPost(post) @@ -313,7 +312,7 @@ func (s SqlPostStore) Get(id string) StoreChannel { pl := model.NewPostList() if len(id) == 0 { - result.Err = model.NewLocAppError("SqlPostStore.GetPost", "store.sql_post.get.app_error", nil, "id="+id) + result.Err = model.NewAppError("SqlPostStore.GetPost", "store.sql_post.get.app_error", nil, "id="+id, http.StatusBadRequest) storeChannel <- result close(storeChannel) return @@ -338,7 +337,7 @@ func (s SqlPostStore) Get(id string) StoreChannel { } if len(rootId) == 0 { - result.Err = model.NewLocAppError("SqlPostStore.GetPost", "store.sql_post.get.app_error", nil, "root_id="+rootId) + result.Err = model.NewAppError("SqlPostStore.GetPost", "store.sql_post.get.app_error", nil, "root_id="+rootId, http.StatusInternalServerError) storeChannel <- result close(storeChannel) return @@ -347,7 +346,7 @@ func (s SqlPostStore) Get(id string) StoreChannel { var posts []*model.Post _, err = s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE (Id = :Id OR RootId = :RootId) AND DeleteAt = 0", map[string]interface{}{"Id": rootId, "RootId": rootId}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetPost", "store.sql_post.get.app_error", nil, "root_id="+rootId+err.Error()) + result.Err = model.NewAppError("SqlPostStore.GetPost", "store.sql_post.get.app_error", nil, "root_id="+rootId+err.Error(), http.StatusInternalServerError) storeChannel <- result close(storeChannel) return @@ -448,7 +447,7 @@ func (s SqlPostStore) Delete(postId string, time int64) StoreChannel { _, err := s.GetMaster().Exec("Update Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "RootId": postId}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.Delete", "store.sql_post.delete.app_error", nil, "id="+postId+", err="+err.Error()) + result.Err = model.NewAppError("SqlPostStore.Delete", "store.sql_post.delete.app_error", nil, "id="+postId+", err="+err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -466,7 +465,7 @@ func (s SqlPostStore) permanentDelete(postId string) StoreChannel { _, err := s.GetMaster().Exec("DELETE FROM Posts WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"Id": postId, "RootId": postId}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.Delete", "store.sql_post.permanent_delete.app_error", nil, "id="+postId+", err="+err.Error()) + result.Err = model.NewAppError("SqlPostStore.Delete", "store.sql_post.permanent_delete.app_error", nil, "id="+postId+", err="+err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -484,7 +483,7 @@ func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) StoreChanne _, err := s.GetMaster().Exec("DELETE FROM Posts WHERE UserId = :UserId AND RootId != ''", map[string]interface{}{"UserId": userId}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.permanentDeleteAllCommentByUser", "store.sql_post.permanent_delete_all_comments_by_user.app_error", nil, "userId="+userId+", err="+err.Error()) + result.Err = model.NewAppError("SqlPostStore.permanentDeleteAllCommentByUser", "store.sql_post.permanent_delete_all_comments_by_user.app_error", nil, "userId="+userId+", err="+err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -517,7 +516,7 @@ func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel { var ids []string _, err := s.GetMaster().Select(&ids, "SELECT Id FROM Posts WHERE UserId = :UserId LIMIT 1000", map[string]interface{}{"UserId": userId}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.PermanentDeleteByUser.select", "store.sql_post.permanent_delete_by_user.app_error", nil, "userId="+userId+", err="+err.Error()) + result.Err = model.NewAppError("SqlPostStore.PermanentDeleteByUser.select", "store.sql_post.permanent_delete_by_user.app_error", nil, "userId="+userId+", err="+err.Error(), http.StatusInternalServerError) storeChannel <- result close(storeChannel) return @@ -537,7 +536,7 @@ func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel { // This is a fail safe, give up if more than 10K messages count = count + 1 if count >= 10 { - result.Err = model.NewLocAppError("SqlPostStore.PermanentDeleteByUser.toolarge", "store.sql_post.permanent_delete_by_user.too_many.app_error", nil, "userId="+userId) + result.Err = model.NewAppError("SqlPostStore.PermanentDeleteByUser.toolarge", "store.sql_post.permanent_delete_by_user.too_many.app_error", nil, "userId="+userId, http.StatusInternalServerError) storeChannel <- result close(storeChannel) return @@ -558,7 +557,7 @@ func (s SqlPostStore) PermanentDeleteByChannel(channelId string) StoreChannel { result := StoreResult{} if _, err := s.GetMaster().Exec("DELETE FROM Posts WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}); err != nil { - result.Err = model.NewLocAppError("SqlPostStore.PermanentDeleteByChannel", "store.sql_post.permanent_delete_by_channel.app_error", nil, "channel_id="+channelId+", "+err.Error()) + result.Err = model.NewAppError("SqlPostStore.PermanentDeleteByChannel", "store.sql_post.permanent_delete_by_channel.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -575,7 +574,7 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int, allowFro result := StoreResult{} if limit > 1000 { - result.Err = model.NewLocAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_posts.app_error", nil, "channelId="+channelId) + result.Err = model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_posts.app_error", nil, "channelId="+channelId, http.StatusBadRequest) storeChannel <- result close(storeChannel) return @@ -699,7 +698,7 @@ func (s SqlPostStore) GetPostsSince(channelId string, time int64, allowFromCache map[string]interface{}{"ChannelId": channelId, "Time": time}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetPostsSince", "store.sql_post.get_posts_since.app_error", nil, "channelId="+channelId+err.Error()) + result.Err = model.NewAppError("SqlPostStore.GetPostsSince", "store.sql_post.get_posts_since.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError) } else { list := model.NewPostList() @@ -791,9 +790,9 @@ func (s SqlPostStore) getPostsAround(channelId string, postId string, numPosts i map[string]interface{}{"ChannelId": channelId, "PostId": postId, "NumPosts": numPosts, "Offset": offset}) if err1 != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get.app_error", nil, "channelId="+channelId+err1.Error()) + result.Err = model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get.app_error", nil, "channelId="+channelId+err1.Error(), http.StatusInternalServerError) } else if err2 != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get_parent.app_error", nil, "channelId="+channelId+err2.Error()) + result.Err = model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get_parent.app_error", nil, "channelId="+channelId+err2.Error(), http.StatusInternalServerError) } else { list := model.NewPostList() @@ -835,7 +834,7 @@ func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) Stor var posts []*model.Post _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt DESC LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_root_posts.app_error", nil, "channelId="+channelId+err.Error()) + result.Err = model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_root_posts.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError) } else { result.Data = posts } @@ -880,7 +879,7 @@ func (s SqlPostStore) getParentsPosts(channelId string, offset int, limit int) S ORDER BY CreateAt`, map[string]interface{}{"ChannelId1": channelId, "Offset": offset, "Limit": limit, "ChannelId2": channelId}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_parents_posts.app_error", nil, "channelId="+channelId+err.Error()) + result.Err = model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_parents_posts.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError) } else { result.Data = posts } @@ -914,7 +913,7 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP list := model.NewPostList() result.Data = list - result.Err = model.NewLocAppError("SqlPostStore.Search", "store.sql_post.search.disabled", nil, fmt.Sprintf("teamId=%v userId=%v params=%v", teamId, userId, params.ToJson())) + result.Err = model.NewAppError("SqlPostStore.Search", "store.sql_post.search.disabled", nil, fmt.Sprintf("teamId=%v userId=%v params=%v", teamId, userId, params.ToJson()), http.StatusNotImplemented) storeChannel <- result close(storeChannel) return @@ -1149,7 +1148,7 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan query, map[string]interface{}{"TeamId": teamId, "StartTime": start, "EndTime": end}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.AnalyticsUserCountsWithPostsByDay", "store.sql_post.analytics_user_counts_posts_by_day.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPostStore.AnalyticsUserCountsWithPostsByDay", "store.sql_post.analytics_user_counts_posts_by_day.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = rows } @@ -1213,7 +1212,7 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel { query, map[string]interface{}{"TeamId": teamId, "StartTime": start, "EndTime": end}) if err != nil { - result.Err = model.NewLocAppError("SqlPostStore.AnalyticsPostCountsByDay", "store.sql_post.analytics_posts_count_by_day.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPostStore.AnalyticsPostCountsByDay", "store.sql_post.analytics_posts_count_by_day.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = rows } @@ -1253,7 +1252,7 @@ func (s SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustH } if v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil { - result.Err = model.NewLocAppError("SqlPostStore.AnalyticsPostCount", "store.sql_post.analytics_posts_count.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPostStore.AnalyticsPostCount", "store.sql_post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = v } @@ -1345,7 +1344,7 @@ func (s SqlPostStore) GetPostsBatchForIndexing(startTime int64, limit int) Store map[string]interface{}{"StartTime": startTime, "NumPosts": limit}) if err1 != nil { - result.Err = model.NewLocAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_batch_for_indexing.get.app_error", nil, err1.Error()) + result.Err = model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_batch_for_indexing.get.app_error", nil, err1.Error(), http.StatusInternalServerError) } else { result.Data = posts } diff --git a/store/sql_preference_store.go b/store/sql_preference_store.go index 667db95fc..bedf7a017 100644 --- a/store/sql_preference_store.go +++ b/store/sql_preference_store.go @@ -4,8 +4,11 @@ package store import ( + "net/http" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/gorp" + "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -64,7 +67,7 @@ func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel { // wrap in a transaction so that if one fails, everything fails transaction, err := s.GetMaster().Begin() if err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.Save", "store.sql_preference.save.open_transaction.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) } else { for _, preference := range *preferences { if upsertResult := s.save(transaction, &preference); upsertResult.Err != nil { @@ -76,13 +79,13 @@ func (s SqlPreferenceStore) Save(preferences *model.Preferences) StoreChannel { if result.Err == nil { if err := transaction.Commit(); err != nil { // don't need to rollback here since the transaction is already closed - result.Err = model.NewLocAppError("SqlPreferenceStore.Save", "store.sql_preference.save.commit_transaction.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = len(*preferences) } } else { if err := transaction.Rollback(); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.Save", "store.sql_preference.save.rollback_transaction.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.Save", "store.sql_preference.save.rollback_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) } } } @@ -119,7 +122,7 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode (:UserId, :Category, :Name, :Value) ON DUPLICATE KEY UPDATE Value = :Value`, params); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.save", "store.sql_preference.save.updating.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.save", "store.sql_preference.save.updating.app_error", nil, err.Error(), http.StatusInternalServerError) } } else if *utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES { // postgres has no way to upsert values until version 9.5 and trying inserting and then updating causes transactions to abort @@ -133,7 +136,7 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode AND Category = :Category AND Name = :Name`, params) if err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.save", "store.sql_preference.save.updating.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.save", "store.sql_preference.save.updating.app_error", nil, err.Error(), http.StatusInternalServerError) return result } @@ -143,8 +146,7 @@ func (s SqlPreferenceStore) save(transaction *gorp.Transaction, preference *mode s.insert(transaction, preference) } } else { - result.Err = model.NewLocAppError("SqlPreferenceStore.save", "store.sql_preference.save.missing_driver.app_error", nil, - "Failed to update preference because of missing driver") + result.Err = model.NewAppError("SqlPreferenceStore.save", "store.sql_preference.save.missing_driver.app_error", nil, "Failed to update preference because of missing driver", http.StatusNotImplemented) } return result @@ -155,11 +157,11 @@ func (s SqlPreferenceStore) insert(transaction *gorp.Transaction, preference *mo if err := transaction.Insert(preference); err != nil { if IsUniqueConstraintError(err, []string{"UserId", "preferences_pkey"}) { - result.Err = model.NewLocAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.exists.app_error", nil, - "user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.exists.app_error", nil, + "user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error(), http.StatusBadRequest) } else { - result.Err = model.NewLocAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.save.app_error", nil, - "user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.insert", "store.sql_preference.insert.save.app_error", nil, + "user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error(), http.StatusInternalServerError) } } @@ -170,8 +172,8 @@ func (s SqlPreferenceStore) update(transaction *gorp.Transaction, preference *mo result := StoreResult{} if _, err := transaction.Update(preference); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.update", "store.sql_preference.update.app_error", nil, - "user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.update", "store.sql_preference.update.app_error", nil, + "user_id="+preference.UserId+", category="+preference.Category+", name="+preference.Name+", "+err.Error(), http.StatusInternalServerError) } return result @@ -194,7 +196,7 @@ func (s SqlPreferenceStore) Get(userId string, category string, name string) Sto UserId = :UserId AND Category = :Category AND Name = :Name`, map[string]interface{}{"UserId": userId, "Category": category, "Name": name}); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.Get", "store.sql_preference.get.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.Get", "store.sql_preference.get.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = preference } @@ -222,7 +224,7 @@ func (s SqlPreferenceStore) GetCategory(userId string, category string) StoreCha WHERE UserId = :UserId AND Category = :Category`, map[string]interface{}{"UserId": userId, "Category": category}); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.GetCategory", "store.sql_preference.get_category.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.GetCategory", "store.sql_preference.get_category.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = preferences } @@ -249,7 +251,7 @@ func (s SqlPreferenceStore) GetAll(userId string) StoreChannel { Preferences WHERE UserId = :UserId`, map[string]interface{}{"UserId": userId}); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.GetAll", "store.sql_preference.get_all.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.GetAll", "store.sql_preference.get_all.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = preferences } @@ -269,7 +271,7 @@ func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel { if _, err := s.GetMaster().Exec( `DELETE FROM Preferences WHERE UserId = :UserId`, map[string]interface{}{"UserId": userId}); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.Delete", "store.sql_preference.permanent_delete_by_user.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.Delete", "store.sql_preference.permanent_delete_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -292,7 +294,7 @@ func (s SqlPreferenceStore) IsFeatureEnabled(feature, userId string) StoreChanne UserId = :UserId AND Category = :Category AND Name = :Name`, map[string]interface{}{"UserId": userId, "Category": model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, "Name": FEATURE_TOGGLE_PREFIX + feature}); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.IsFeatureEnabled", "store.sql_preference.is_feature_enabled.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.IsFeatureEnabled", "store.sql_preference.is_feature_enabled.app_error", nil, err.Error(), http.StatusInternalServerError) } else { result.Data = value == "true" } @@ -317,7 +319,7 @@ func (s SqlPreferenceStore) Delete(userId, category, name string) StoreChannel { UserId = :UserId AND Category = :Category AND Name = :Name`, map[string]interface{}{"UserId": userId, "Category": category, "Name": name}); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.Delete", "store.sql_preference.delete.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.Delete", "store.sql_preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -339,7 +341,7 @@ func (s SqlPreferenceStore) DeleteCategory(userId string, category string) Store WHERE UserId = :UserId AND Category = :Category`, map[string]interface{}{"UserId": userId, "Category": category}); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.DeleteCategory", "store.sql_preference.delete.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.DeleteCategory", "store.sql_preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) } storeChannel <- result @@ -361,7 +363,7 @@ func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string) WHERE Name = :Name AND Category = :Category`, map[string]interface{}{"Name": name, "Category": category}); err != nil { - result.Err = model.NewLocAppError("SqlPreferenceStore.DeleteCategoryAndName", "store.sql_preference.delete.app_error", nil, err.Error()) + result.Err = model.NewAppError("SqlPreferenceStore.DeleteCategoryAndName", "store.sql_preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) } storeChannel <- result |