Adhere to convention while writing insights response (#21602)

Этот коммит содержится в:
Shivashis Padhi
2022-12-04 21:20:51 +05:30
коммит произвёл GitHub
родитель 06e964b86b
Коммит b0804f26ef

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

@@ -89,13 +89,10 @@ func getTopReactionsForTeamSince(c *Context, w http.ResponseWriter, r *http.Requ
return return
} }
js, err := json.Marshal(topReactionList) if err := json.NewEncoder(w).Encode(topReactionList); err != nil {
if err != nil { c.Err = model.NewAppError("getTopReactionsForTeamSince", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("getTopReactionsForTeamSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return return
} }
w.Write(js)
} }
func getTopReactionsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { func getTopReactionsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -149,13 +146,10 @@ func getTopReactionsForUserSince(c *Context, w http.ResponseWriter, r *http.Requ
return return
} }
js, err := json.Marshal(topReactionList) if err := json.NewEncoder(w).Encode(topReactionList); err != nil {
if err != nil { c.Err = model.NewAppError("getTopReactionsForUserSince", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("getTopReactionsForUserSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return return
} }
w.Write(js)
} }
// Top Channels // Top Channels
@@ -218,13 +212,10 @@ func getTopChannelsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reque
return return
} }
js, err := json.Marshal(topChannels) if err := json.NewEncoder(w).Encode(topChannels); err != nil {
if err != nil { c.Err = model.NewAppError("getTopChannelsForTeamSince", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("getTopChannelsForTeamSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return return
} }
w.Write(js)
} }
func getTopChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { func getTopChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -285,13 +276,10 @@ func getTopChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Reque
return return
} }
js, jsonErr := json.Marshal(topChannels) if err := json.NewEncoder(w).Encode(topChannels); err != nil {
if jsonErr != nil { c.Err = model.NewAppError("getTopChannelsForUserSince", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("getTopChannelsForUserSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
return return
} }
w.Write(js)
} }
// Top Threads // Top Threads
@@ -347,13 +335,10 @@ func getTopThreadsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reques
return return
} }
js, jsonError := json.Marshal(topThreads) if err := json.NewEncoder(w).Encode(topThreads); err != nil {
if jsonError != nil { c.Err = model.NewAppError("getTopThreadsForTeamSince", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("getTopThreadsForTeamSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return return
} }
w.Write(js)
} }
func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) { func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -407,13 +392,10 @@ func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Reques
return return
} }
js, jsonErr := json.Marshal(topThreads) if err := json.NewEncoder(w).Encode(topThreads); err != nil {
if jsonErr != nil { c.Err = model.NewAppError("getTopThreadsForUserSince", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("getTopThreadsForUserSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
return return
} }
w.Write(js)
} }
// Top DMs // Top DMs
@@ -448,13 +430,10 @@ func getTopDMsForUserSince(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
js, jsonErr := json.Marshal(topDMs) if err := json.NewEncoder(w).Encode(topDMs); err != nil {
if jsonErr != nil { c.Err = model.NewAppError("getTopDMsForUserSince", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("getTopDMsForUserSince", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
return return
} }
w.Write(js)
} }
// Top Channels // Top Channels
@@ -651,11 +630,8 @@ func getNewTeamMembersSince(c *Context, w http.ResponseWriter, r *http.Request)
ntms.TotalCount = count ntms.TotalCount = count
js, jsonErr := json.Marshal(ntms) if err := json.NewEncoder(w).Encode(ntms); err != nil {
if jsonErr != nil { c.Err = model.NewAppError("getNewTeamembersForTeamSince", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("getNewTeamembersForTeamSince", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
return return
} }
w.Write(js)
} }